Skip to main content

graph

Attribute Macro graph 

Source
#[graph]
Expand description

Build the function’s await dependency graph and run independent work concurrently.

Options:

  • bound = N caps concurrent loop iterations (default 16);
  • explain prints the graph at compile time;
  • off compiles the function as written (for comparisons; PSYNC_GRAPH=off does it for all);
  • strict treats awaited calls psync cannot classify as writes to an unknown resource;
  • calls = read | write | write_independent | independent marks the whole function: how unclassified awaited calls are taken (overriding strict), and, for the independent forms, that every statement’s effects commute with the others’;
  • speculate lets writes run before earlier exits everywhere in the function;
  • effects(read(a, ..), write(b, ..), ordered(c, ..)) names more verbs for the effect analysis;
  • yield_every = N makes every loop of async code yield to the executor every N iterations (preemption points for cooperative executors);
  • crate = path names the psync crate in generated code.

Hints inside the function: #[psync::seq], #[psync::fresh], #[psync::independent], #[psync::speculate].

ⓘ
#[psync::graph(bound = 8)]
async fn sizes(store: &Store, keys: &[String]) -> Result<u64, Error> {
    let mut total = 0;
    for key in keys {
        total += store.head(key).await?.size; // up to 8 HEADs in flight
    }
    Ok(total)
}