Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nxy7/async-utils
https://github.com/nxy7/async-utils
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/nxy7/async-utils
- Owner: nxy7
- Created: 2024-03-05T19:52:25.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-03-05T20:31:35.000Z (10 months ago)
- Last Synced: 2024-12-23T00:54:38.537Z (17 days ago)
- Language: Rust
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Async Utils
Simple crate created out of need to manage my Tokio JoinHandles. Async runtimes get to decide how they treat spawned tasks and
Tokio went with the model that detaches spawned Tasks. Regardless of the fact if You think that's good choice, to avoid leaking
tasks and for easier task management it's useful to have tasks 'attached' to some handle and cancel them on handle drop.
This makes structured concurrency much easier, as you don't have to manually send values down some channels and instead you just
need to make sure that parent task is holding TaskHandle of child and doesn't drop it.
That's where this crate is primarily coming from. Right now it provides 3 (actually 2) structs to help to manage concurrency.## Provided types
- TaskHandle - wrapper around JoinHandle, that can be obtained by calling `to_task_handle()` on tokio::task::JoinHandle. Aborts inner task on Drop.
- TaskSet - alias for Tokio JoinSet. Tokio JoinSet already aborts tasks on Drop.
- TaskMap - wrapper around HashMap>. Useful if you want more control over your 'Set' of tasks as it makes it easier to see if
there is already some task spawned.All those types abort tasks when they are dropped. In the future I might put here more 'async' utilities that I find useful in my every day coding.