Skip to main content

WorkerJob

Trait WorkerJob 

Source
pub trait WorkerJob: Copy + 'static {
    type Input: WorkerData;
    type Output: WorkerData;

    const NAME: &'static str;

    // Required method
    fn run(input: Self::Input) -> Self::Output;
}
Expand description

A function withBlocking runs off the UI thread on every platform: on a pool thread where the platform has threads, in a Web Worker in a browser. The #[worker_job] attribute implements it for a function, and the function’s with makes the call withBlocking takes:

ⓘ
#[worker_job]
fn word_count(text: String) -> u32 {
    text.split_whitespace().count() as u32
}

scope.launch(async move {
    if let Ok(count) = withBlocking(word_count.with(text)).await {
        shown.set(count);
    }
});

Required Associated Constants§

Source

const NAME: &'static str

The job’s name, one of a kind in the app: a Web Worker finds the job by it.

Required Associated Types§

Source

type Input: WorkerData

What the job takes.

Source

type Output: WorkerData

What the job returns.

Required Methods§

Source

fn run(input: Self::Input) -> Self::Output

Does the work.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§