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§
- Identifier to send output to bridges.
- Hook handle for the
use_worker_bridge
hook. - Hook handle for the
use_worker_subscription
hook. - A connection manager for components interaction with workers.
- A handle that closes the worker when it is dropped.
- The Worker Agent Provider.
- Properties for WorkerProvider.
- A Worker Registrar.
- This struct holds a reference to a component and to a global scheduler.
Traits§
- Declares the behaviour of a worker.