Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewbaxter/taskmanager
Rust background task group manager
https://github.com/andrewbaxter/taskmanager
Last synced: about 23 hours ago
JSON representation
Rust background task group manager
- Host: GitHub
- URL: https://github.com/andrewbaxter/taskmanager
- Owner: andrewbaxter
- License: isc
- Created: 2022-10-07T13:31:43.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-03T15:03:32.000Z (4 months ago)
- Last Synced: 2024-10-30T14:54:54.419Z (18 days ago)
- Language: Rust
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
This is a tool for managing asynchronous tasks.
For example, maybe you have some periodic background tasks, plus a couple web servers. Using a `TaskManager` you can group these and shut them down as a group, gracefully, and wait for them all to end.
Handles
- Long tasks
- Simple periodic tasks (fixed sleep between invocations)
- Async streams
- Ctrl+c shutdownUse it like
```rust
let tm = TaskManager::new();
tm.attach_sigint({
log2 = logger.clone();
|e| log2.err("Error handling sigint", e)
});
let tm1 = tm.clone();
let log2 = logger.clone();
tm.task(async move {
match tm1.if_alive(server).await {
Some(r) => match r {
Ok(_) => {} // Server exited normally
Err(e) => {
log.err("Server died with error", e);
}
},
None => {} // Received shutdown
};
});tm.join().await;
```