-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom thread Handle for sub-thread services
- Loading branch information
1 parent
8a2e291
commit 98faa22
Showing
5 changed files
with
50 additions
and
13 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
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,34 @@ | ||
//! # Handler | ||
//! | ||
//! Error/kill handler for sub threads and services | ||
use std::thread; | ||
|
||
use futures::sync::oneshot; | ||
|
||
/// Handler struct responsible for sending a stop signal to a service and | ||
/// joining a thread back to the main thread | ||
pub struct Handle<'a> { | ||
/// Channel to send kill signal | ||
tx: oneshot::Sender<()>, | ||
/// Service thread handler | ||
thread: thread::JoinHandle<()>, | ||
/// Service name | ||
name: &'a str, | ||
} | ||
|
||
impl<'a> Handle<'a> { | ||
/// Return new handle instance | ||
pub fn new(tx: oneshot::Sender<()>, thread: thread::JoinHandle<()>, name: &str) -> Handle { | ||
Handle { tx, thread, name } | ||
} | ||
|
||
/// Handle sending a stop signal to the service and joining the service | ||
/// thread | ||
pub fn stop(self) { | ||
self.tx | ||
.send(()) | ||
.expect(&format!("failed sending shutdown signal to {}", self.name)); | ||
self.thread.join().expect(&format!("{} join failed", self.name)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
pub mod checks; | ||
pub mod doc_format; | ||
pub mod handler; | ||
pub mod ocean; | ||
#[cfg(test)] | ||
pub mod testing; |