| Crates.io | async_tasks_state_map |
| lib.rs | async_tasks_state_map |
| version | 1.0.1 |
| created_at | 2024-02-24 07:32:40.981883+00 |
| updated_at | 2024-02-27 10:13:32.269963+00 |
| description | A struct for recording execution status of async tasks with async methods. |
| homepage | |
| repository | https://github.com/Ayana-chan/async_tasks_state_map |
| max_upload_size | |
| id | 1151440 |
| size | 36,691 |
A struct for recording execution status of async tasks with async methods.
Functions:
Futures and query whether they are
not found, running, successful, failed, or revoking.Futures to revoke the succeeded Futures and make them not found.Dependency:
tokio with feature rt, so cannot use other async runtimes.HashMap.Use this crate if:
task_id (not necessarily String) for a future (task).task_id to succeed more than once.A recorder can only use single task_id type. The type of task_id should be:
Eq + Hash + Clone + Send + Sync + 'staticArc) (only cloned once when launch).async_tasks_recorder is another implement depending on
HashSet, which is easier to iterate every task in the same state. But you should not use that crate if you only focus on iterating only one state. Instead, you can collect the tasks in certain state into an externalArc<HashSet>.
┌------- Revoking ←-----┐
↓ |
NotFound --> Working --> Success
↑ |
| ↓
Failed
NotFound or Failed.Success.NotFound can be equivalent to Failed.Revoking can be equivalent to Success.So you may get:
┌----------------------┐
↓ |
Failed <--> Working --> Success
Arc to store task_idIf you don't use Arc, all task_id is stored in scc::HashMap.
But it has to be cloned when query or update the task's state.
However, if you use Arc, only Arc is stored in scc::HashMap,
and the task_id is stored in heap independently,
which may cause additional memory overhead.
Make your own decision on whether to use Arc or not.