Async DAG
async_dag is an async task scheduling utility.
When async tasks and their dependencies can be described by a DAG, this crate ensures the tasks are run at maximum posiible parallelism.
Example
Say there are several tasks which either produces an i32 or sums two i32s,
and they have dependency relationship described by following graph,
7
/ \
3 \
/ \ \
1 2 4
which means there are three tasks producing value 1, 2 and 4,
a task summing 1 and 2 to get 3,
and a task summing 3 and 4 to get the final output, 7.
A casual developer may write
let _3 = sum.await;
let _7 = sum.await;
Above code is inefficient because every task only begins after the previous one completes.
A better version would be
let = join!.await;
let _3 = sum.await;
let _7 = sum.await;
where _1, _2 and _4 run in parallel.
However, above scheduling is still not optimal
because the summing of _1 and _2 can run in parallel with _4.
To acheive maximum parallelism, one has to write something like
let _1_2 = join!;
let = select!
let _7 = sum.await;
The code is quite obscure and the manual scheduling quickly becomes tiring, if possible at all, with a few more tasks and dependencies.
With async_dag, one can write
use Graph;
async
async
use block_on;
block_on;
Fail-fast graphs
TryGraph can be used if the user wants a fail-fast strategy with fallible tasks.
It aborts running futures when any one of them completes with a Err.
Dev
pre-commit hook setup: cargo run --bin install-pre-commit-hook.