This is unreleased documentation for Yew Next version.
For up-to-date documentation, see the latest version on docs.rs.

yew_agent/
lib.rs

1//! This module contains Yew's web worker implementation.
2//!
3//! ## Types
4//!
5//! There're a couple kinds of agents:
6//!
7//! #### Oneshot
8//!
9//! A kind of agent that for each input, a single output is returned.
10//!
11//! #### Reactor
12//!
13//! A kind of agent that can send many inputs and receive many outputs over a single bridge.
14//!
15//! #### Worker
16//!
17//! The low-level implementation of agents that provides an actor model and communicates with
18//! multiple bridges.
19//!
20//! ## Reachability
21//!
22//! When an agent is spawned, each agent is associated with a reachability.
23//!
24//! #### Private
25//!
26//! Each time a bridge is created, a new instance
27//! of agent is spawned. This allows parallel computing between agents.
28//!
29//! #### Public
30//!
31//! Public agents are shared among all children of a provider.
32//! Only 1 instance will be spawned for each public agents provider.
33//!
34//! ### Provider
35//!
36//! Each Agent requires a provider to provide communications and maintain bridges.
37//! All hooks must be called within a provider.
38//!
39//! ## Communications with Agents
40//!
41//! Hooks provides means to communicate with agent instances.
42//!
43//! #### Bridge
44//!
45//! See: [`use_worker_bridge`](worker::use_worker_bridge),
46//! [`use_reactor_bridge`](reactor::use_reactor_bridge)
47//!
48//! A bridge takes a callback to receive outputs from agents
49//! and provides a handle to send inputs to agents.
50//!
51//! #### Subscription
52//!
53//! See: [`use_worker_subscription`](worker::use_worker_subscription),
54//! [`use_reactor_subscription`](reactor::use_reactor_subscription)
55//!
56//! Similar to bridges, a subscription produces a handle to send inputs to agents. However, instead
57//! of notifying the receiver with a callback, it collect all outputs into a slice.
58//!
59//! #### Runner
60//!
61//! See: [`use_oneshot_runner`](oneshot::use_oneshot_runner)
62//!
63//! Unlike other agents, oneshot bridges provide a `use_oneshot_runner` hook to execute oneshot
64//! agents on demand.
65
66#![deny(
67    clippy::all,
68    missing_docs,
69    missing_debug_implementations,
70    bare_trait_objects,
71    anonymous_parameters,
72    elided_lifetimes_in_paths
73)]
74
75extern crate self as yew_agent;
76
77pub mod oneshot;
78pub mod reactor;
79pub mod worker;
80
81#[doc(inline)]
82pub use gloo_worker::{Bincode, Codec, Registrable, Spawnable};
83
84mod reach;
85pub mod scope_ext;
86
87pub use reach::Reach;
88
89mod utils;
90
91#[doc(hidden)]
92pub mod __vendored {
93    pub use futures;
94}
95
96pub mod prelude {
97    //! Prelude module to be imported when working with `yew-agent`.
98    //!
99    //! This module re-exports the frequently used types from the crate.
100    pub use crate::oneshot::{oneshot, use_oneshot_runner, UseOneshotRunnerHandle};
101    pub use crate::reach::Reach;
102    pub use crate::reactor::{
103        reactor, use_reactor_bridge, use_reactor_subscription, ReactorEvent, ReactorScope,
104        UseReactorBridgeHandle, UseReactorSubscriptionHandle,
105    };
106    pub use crate::scope_ext::{AgentScopeExt, ReactorBridgeHandle, WorkerBridgeHandle};
107    pub use crate::worker::{
108        use_worker_bridge, use_worker_subscription, UseWorkerBridgeHandle,
109        UseWorkerSubscriptionHandle, WorkerScope,
110    };
111    pub use crate::{Registrable, Spawnable};
112}