-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #506 from interlay/nakul/fix_merge_service_crate
fix: merge service crate
- Loading branch information
Showing
25 changed files
with
298 additions
and
316 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ members = [ | |
"vault", | ||
"bitcoin", | ||
"faucet", | ||
"service", | ||
"runner" | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod error; | ||
mod http; | ||
mod service; | ||
|
||
use clap::Parser; | ||
use error::Error; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use futures::{future::Either, Future, FutureExt}; | ||
pub use runtime::{ShutdownReceiver, ShutdownSender}; | ||
|
||
pub enum TerminationStatus<Res> { | ||
Cancelled, | ||
Completed(Res), | ||
} | ||
|
||
pub async fn on_shutdown(shutdown_tx: ShutdownSender, future2: impl Future) { | ||
let mut shutdown_rx = shutdown_tx.subscribe(); | ||
let future1 = shutdown_rx.recv().fuse(); | ||
|
||
let _ = future1.await; | ||
future2.await; | ||
} | ||
|
||
async fn run_cancelable<F, Res>(mut shutdown_rx: ShutdownReceiver, future2: F) -> TerminationStatus<Res> | ||
where | ||
F: Future<Output = Res>, | ||
{ | ||
let future1 = shutdown_rx.recv().fuse(); | ||
let future2 = future2.fuse(); | ||
|
||
futures::pin_mut!(future1); | ||
futures::pin_mut!(future2); | ||
|
||
match futures::future::select(future1, future2).await { | ||
Either::Left((_, _)) => TerminationStatus::Cancelled, | ||
Either::Right((res, _)) => TerminationStatus::Completed(res), | ||
} | ||
} | ||
|
||
pub async fn wait_or_shutdown<F, E>(shutdown_tx: ShutdownSender, future2: F) -> Result<(), E> | ||
where | ||
F: Future<Output = Result<(), E>>, | ||
{ | ||
match run_cancelable(shutdown_tx.subscribe(), future2).await { | ||
TerminationStatus::Cancelled => { | ||
tracing::trace!("Received shutdown signal"); | ||
Ok(()) | ||
} | ||
TerminationStatus::Completed(res) => { | ||
tracing::trace!("Sending shutdown signal"); | ||
let _ = shutdown_tx.send(()); | ||
res | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.