Module gloo_worker::reactor

source ·
Expand description

A future-based worker that can consume many inputs and produce many outputs.

Example

use gloo_worker::reactor::{reactor, ReactorScope};
use gloo_worker::Spawnable;
use futures::{sink::SinkExt, StreamExt};

#[reactor]
async fn SquaredOnDemand(mut scope: ReactorScope<u64, u64>) {
    while let Some(m) = scope.next().await {
        if scope.send(m.pow(2)).await.is_err() {
            break;
        }
    }
}
let mut bridge = SquaredOnDemand::spawner().spawn("...");

bridge.send_input(2);

assert_eq!(bridge.next().await, Some(4));
assert_eq!(bridge.next().await, None);

Structs

Enums

Traits

  • A reactor worker.
  • A helper trait to extract the input and output type from a [ReactorStream].

Attribute Macros