Trait gloo_worker::Worker

source ·
pub trait Worker: Sized {
    type Message;
    type Input;
    type Output;

    // Required methods
    fn create(scope: &WorkerScope<Self>) -> Self;
    fn update(&mut self, scope: &WorkerScope<Self>, msg: Self::Message);
    fn received(
        &mut self,
        scope: &WorkerScope<Self>,
        msg: Self::Input,
        id: HandlerId
    );

    // Provided methods
    fn connected(&mut self, scope: &WorkerScope<Self>, id: HandlerId) { ... }
    fn disconnected(&mut self, scope: &WorkerScope<Self>, id: HandlerId) { ... }
    fn destroy(
        &mut self,
        scope: &WorkerScope<Self>,
        destruct: WorkerDestroyHandle<Self>
    ) { ... }
}
Expand description

Declares the behaviour of a worker.

Required Associated Types§

source

type Message

Update message type.

source

type Input

Incoming message type.

source

type Output

Outgoing message type.

Required Methods§

source

fn create(scope: &WorkerScope<Self>) -> Self

Creates an instance of a worker.

source

fn update(&mut self, scope: &WorkerScope<Self>, msg: Self::Message)

Receives an update.

This method is called when the worker send messages to itself via WorkerScope::send_message.

source

fn received( &mut self, scope: &WorkerScope<Self>, msg: Self::Input, id: HandlerId )

Receives an input from a connected bridge.

When a bridge sends an input via WorkerBridge::send, the worker will receive the input via this method.

Provided Methods§

source

fn connected(&mut self, scope: &WorkerScope<Self>, id: HandlerId)

New bridge created.

When a new bridge is created by WorkerSpawner::spawn or WorkerBridge::fork, the worker will be notified the HandlerId of the created bridge via this method.

source

fn disconnected(&mut self, scope: &WorkerScope<Self>, id: HandlerId)

Existing bridge destroyed.

When a bridge is dropped, the worker will be notified with this method.

source

fn destroy( &mut self, scope: &WorkerScope<Self>, destruct: WorkerDestroyHandle<Self> )

Destroys the current worker.

When all bridges are dropped, the method will be invoked.

This method is provided a destroy handle where when it is dropped, the worker is closed. If the worker is closed immediately, then it can ignore the destroy handle. Otherwise hold the destroy handle until the clean up task is finished.

Note

This method will only be called after all bridges are disconnected. Attempting to send messages after this method is called will have no effect.

Object Safety§

This trait is not object safe.

Implementors§