Expand description
This module contains the reactor agent implementation.
Reactor agents are agents that receive multiple inputs and send multiple outputs over a single bridge. A reactor is defined as an async function that takes a ReactorScope as the argument.
The reactor scope is a stream that produces inputs from the bridge and a sink that implements an additional send method to send outputs to the connected bridge. When the bridge disconnects, the output stream and input sink will be closed.
§Example
use futures::sink::SinkExt;
use futures::stream::StreamExt;
use yew_agent::reactor::{reactor, ReactorScope};
#[reactor(MyReactor)]
pub async fn my_reactor(mut scope: ReactorScope<ReactorInput, ReactorOutput>) {
while let Some(input) = scope.next().await {
// handles each input.
// ...
// sends output
if scope.send(output).await.is_err() {
// sender closed, the bridge is disconnected
break;
}
}
}
Structs§
- Reactor
Bridge - A connection manager for components interaction with oneshot workers.
- Reactor
Provider - The Reactor Agent Provider.
- Reactor
Registrar - A registrar for reactor workers.
- Reactor
Scope - A handle to communicate with bridges.
- Reactor
Spawner - A spawner to create oneshot workers.
- UseReactor
Bridge Handle - Hook handle for the
use_reactor_bridge
hook. - UseReactor
Subscription Handle - Hook handle for the
use_reactor_subscription
hook.
Enums§
- Reactor
Event - A type that represents events from a reactor.
Traits§
- Reactor
- A reactor worker.
- Reactor
Scoped - A helper trait to extract the input and output type from a [ReactorStream].
Functions§
- use_
reactor_ bridge - A hook to bridge to a
Reactor
. - use_
reactor_ subscription - A hook to subscribe to the outputs of a Reactor agent.
Attribute Macros§
- reactor
- A procedural macro to create reactor agents.