Crates.io | async_tasks_state_map |
lib.rs | async_tasks_state_map |
version | 1.0.1 |
source | src |
created_at | 2024-02-24 07:32:40.981883 |
updated_at | 2024-02-27 10:13:32.269963 |
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:
Future
s and query whether they are
not found, running, successful, failed, or revoking.Future
s to revoke the succeeded Future
s 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 + 'static
Arc
) (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_id
If 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.