-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add monitor loop to supervisor logic (#9)
* add monitor loop to supervisor logic * add run method to supervisor::Spec * add SupervisorResult enum type Co-authored-by: Zephyr Shannon <geoffpshannon@gmail.com>
- Loading branch information
1 parent
963a23f
commit 21282c1
Showing
7 changed files
with
377 additions
and
99 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use tokio::sync::oneshot; | ||
|
||
/// StartNotifier offers a convenient way to notify a supervising task that this | ||
/// task got started or that it failed to start. | ||
pub struct StartNotifier<T, E>(Box<dyn FnOnce(Result<T, E>) + Send>); | ||
|
||
impl<T, E> StartNotifier<T, E> { | ||
pub fn from_oneshot(sender: oneshot::Sender<Result<T, E>>) -> Self | ||
where | ||
T: Send + 'static, | ||
E: Send + 'static, | ||
{ | ||
StartNotifier(Box::new(move |err| { | ||
sender.send(err).ok(); | ||
})) | ||
} | ||
|
||
fn call(self, err: Result<T, E>) { | ||
self.0(err) | ||
} | ||
|
||
pub fn success(self, result: T) { | ||
self.call(Ok(result)) | ||
} | ||
|
||
pub fn failed(self, err: E) { | ||
self.call(Err(err)) | ||
} | ||
} |
Oops, something went wrong.