gloo_worker/lib.rs
1//! Workers are a way to offload tasks to web workers. These are run concurrently using
2//! [web-workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers).
3//!
4//! # Communicating with workers
5//!
6//! ### Bridges
7//!
8//! After a Worker is spawned, a bridge is created.
9//! A Bridge allows bi-directional communication between an worker and a component.
10//! Bridges also allow workers to communicate with one another.
11//!
12//! ### Scopes
13//!
14//! Scopes are used by workers to communicates with bridges and send updates to itself after
15//! a task is finished.
16//!
17//! ### Overhead
18//!
19//! Gloo Workers use web workers. They incur a serialization overhead on the
20//! messages they send and receive. Bridges use [bincode](https://github.com/servo/bincode)
21//! by default to communicate with workers, so the cost is substantially higher
22//! than just calling a function.
23//!
24//! # API
25//!
26//! The API is exposed in two different ways.
27//! 1. Using the `Worker` trait.
28//! 2. Using the `#[oneshot]` and `#[reactor]` macros.
29//!
30//! ## Worker trait
31//!
32//! The [`Worker`] trait is the core of the API. It allows you to spawn workers and communicate
33//! with them. It provides an actor model to communicate with for workers.
34//!
35//! See the [`Worker`] trait for more information.
36//!
37//! ## Macros
38//!
39//! The macros provide a function-like syntax to spawn workers and communicate with them.
40//! There are two macros:
41//! 1. [`#[oneshot]`](oneshot) - Worker where each input produces a single output.
42//! 2. [`#[reactor]`](reactor) - Worker that receives input(s) and may produce output(s).
43
44#![deny(
45 clippy::all,
46 missing_docs,
47 missing_debug_implementations,
48 bare_trait_objects,
49 anonymous_parameters,
50 elided_lifetimes_in_paths
51)]
52#![cfg_attr(docsrs, feature(doc_cfg))]
53
54mod actor;
55mod codec;
56#[cfg(feature = "futures")]
57pub mod oneshot;
58#[cfg(feature = "futures")]
59pub mod reactor;
60mod traits;
61
62pub use actor::*;
63pub use codec::{Bincode, Codec};
64pub use traits::*;