forked from lavina/lavina
1
0
Fork 0

Compare commits

...

3 Commits

Author SHA1 Message Date
Nikita Vilunov 63024c7586 wip 2024-01-31 11:36:56 +01:00
Nikita Vilunov de2d0b967c test 2024-01-30 11:37:22 +01:00
Nikita Vilunov b29fb68e8f fix links 2024-01-29 23:17:08 +01:00
2 changed files with 9 additions and 4 deletions

View File

@ -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,

View File

@ -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