Crate gloo_worker

Source
Expand description

Workers are a way to offload tasks to web workers. These are run concurrently using web-workers.

§Communicating with workers

§Bridges

After a Worker is spawned, a bridge is created. A Bridge allows bi-directional communication between an worker and a component. Bridges also allow workers to communicate with one another.

§Scopes

Scopes are used by workers to communicates with bridges and send updates to itself after a task is finished.

§Overhead

Gloo Workers use web workers. They incur a serialization overhead on the messages they send and receive. Bridges use bincode by default to communicate with workers, so the cost is substantially higher than just calling a function.

§API

The API is exposed in two different ways.

  1. Using the Worker trait.
  2. Using the #[oneshot] and #[reactor] macros.

§Worker trait

The Worker trait is the core of the API. It allows you to spawn workers and communicate with them. It provides an actor model to communicate with for workers.

See the Worker trait for more information.

§Macros

The macros provide a function-like syntax to spawn workers and communicate with them. There are two macros:

  1. #[oneshot] - Worker where each input produces a single output.
  2. #[reactor] - Worker that receives input(s) and may produce output(s).

Modules§

oneshot
A future-based worker that for each input, one output is produced.
reactor
A future-based worker that can consume many inputs and produce many outputs.

Structs§

Bincode
Default message encoding with bincode.
HandlerId
Identifier to send output to bridges.
WorkerBridge
A connection manager for components interaction with workers.
WorkerDestroyHandle
A handle that closes the worker when it is dropped.
WorkerRegistrar
A Worker Registrar.
WorkerScope
This struct holds a reference to a component and to a global scheduler.
WorkerSpawner
A spawner to create workers.

Traits§

Codec
Message Encoding and Decoding Format
Registrable
A trait to enable public workers being registered in a web worker.
Spawnable
A Worker that can be spawned by a spawner.
Worker
Declares the behaviour of a worker.