forked from lavina/lavina
Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Nikita Vilunov | 63024c7586 | |
Nikita Vilunov | de2d0b967c | |
Nikita Vilunov | b29fb68e8f |
|
@ -1,10 +1,12 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
/// A handle to a task that can be gracefully terminated.
|
||||
pub struct Terminator {
|
||||
signal: Promise<()>,
|
||||
completion: JoinHandle<Result<()>>,
|
||||
}
|
||||
impl Terminator {
|
||||
/// Send a signal to the task to terminate and await its completion.
|
||||
pub async fn terminate(self) -> Result<()> {
|
||||
match self.signal.send(()) {
|
||||
Ok(()) => {}
|
||||
|
@ -14,7 +16,10 @@ impl Terminator {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Used to spawn managed tasks with support for graceful shutdown
|
||||
/// Spawn a task with support for graceful shutdown.
|
||||
///
|
||||
/// The launched task must listen for the termination signal and stop gracefully on receiving it.
|
||||
/// The signal is sent by calling the `terminate` method on the returned `Terminator` instance outside the task.
|
||||
pub fn spawn<Fun, Fut>(launcher: Fun) -> Terminator
|
||||
where
|
||||
Fun: FnOnce(Deferred<()>) -> Fut,
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
Multiprotocol chat server based on open protocols.
|
||||
|
||||
- [How to run Lavina locally](docs/running.md)
|
||||
- [Architectural diagrams](docs/flow.md)
|
||||
- [Project structure](crates/readme.md)
|
||||
- [How to run Lavina locally](/docs/running.md)
|
||||
- [Architectural diagrams](/docs/flow.md)
|
||||
- [Project structure](crates)
|
||||
|
||||
## Goals
|
||||
|
||||
|
|
Loading…
Reference in New Issue