reactive-graph / reactive-graph

Reactive Graph and Flow Control
https://reactive-graph.io/
MIT License
12 stars 1 forks source link

Experiment: Async Reactive Streams #69

Open aschaeffer opened 1 year ago

aschaeffer commented 1 year ago

Problem

Idea

The GraphQL API is async already. If the reactive streams would be async, it would be possible to avoid blocking completely and further increase performance.

Research tasks

This may work or not - the goal is to get an idea if it would be possible.

aschaeffer commented 1 year ago

This may take a while until support for async closures land in rust:

Current (sync)

type Subscriber<'a, Sig> = (u128, dyn FnMut(&Sig) + Send + 'a);
subscribers_mut.par_iter_mut().for_each(|sub| sub.1(signal));

Goal (async)

type Subscriber<'a, Sig> = (u128, async dyn FnMut(&Sig) + Send + 'a);
let mut tasks = Vec::new();
for subscriber in subscribers_mut.iter_mut() {
  tokio::spawn(async {
    tasks.push(subscriber(signal).await);
  }
}
tasks.join_all();