Expand description
This module contains the worker agent implementation.
This is a low-level implementation that uses an actor model.
§Example
use serde::{Deserialize, Serialize};
use yew::prelude::*;
use yew_agent::worker::{use_worker_bridge, UseWorkerBridgeHandle};
// This would usually live in the same file as your worker
#[derive(Serialize, Deserialize)]
pub enum WorkerResponseType {
IncrementCounter,
}
use my_worker_mod::MyWorker; // note that <MyWorker as yew_agent::Worker>::Output == WorkerResponseType
#[function_component(UseWorkerBridge)]
fn bridge() -> Html {
let counter = use_state(|| 0);
// a scoped block to clone the state in
{
let counter = counter.clone();
// response will be of type MyWorker::Output, i.e. WorkerResponseType
let bridge: UseWorkerBridgeHandle<MyWorker> = use_worker_bridge(move |response| match response {
WorkerResponseType::IncrementCounter => {
counter.set(*counter + 1);
}
});
}
html! {
<div>
{*counter}
</div>
}
}
Structs§
- Handler
Id - Identifier to send output to bridges.
- UseWorker
Bridge Handle - Hook handle for the
use_worker_bridge
hook. - UseWorker
Subscription Handle - Hook handle for the
use_worker_subscription
hook. - Worker
Bridge - A connection manager for components interaction with workers.
- Worker
Destroy Handle - A handle that closes the worker when it is dropped.
- Worker
Provider - The Worker Agent Provider.
- Worker
Provider Props - Properties for WorkerProvider.
- Worker
Registrar - A Worker Registrar.
- Worker
Scope - This struct holds a reference to a component and to a global scheduler.
Traits§
- Worker
- Declares the behaviour of a worker.
Functions§
- use_
worker_ bridge - A hook to bridge to a
Worker
. - use_
worker_ subscription - A hook to subscribe to the outputs of a Worker agent.