Singleflight Async
Singleflight in async style.
Key Features
- Execute an async task only once for the same key at the same time.
- Cancel safe when the task is dropped.
- Not requires the future to be
Send
/Sync
, or'static
. - Works for all kind of runtimes including tokio, monoio, or others.
Example
use SingleFlight;
async
The output will be like:
will sleep to simulate async task
real task done
task finished
task finished
task finished
task finished
task finished
task finished
task finished
task finished
task finished
task finished
time elapsed: 100.901321ms