[][src]Struct web_worker::WorkerPool

pub struct WorkerPool { /* fields omitted */ }

The WorkerPool. This is a special type of thread pool that works on wasm and provide a way to run work they way rayon does it.

Implementations

impl WorkerPool[src]

pub fn new(initial: usize) -> Result<WorkerPool, JsValue>[src]

Creates a new WorkerPool which immediately creates initial workers.

The pool created here can be used over a long period of time, and it will be initially primed with initial workers. Currently workers are never released or gc'd until the whole pool is destroyed.

Errors

Returns any error that may happen while a JS web worker is created and a message is sent to it.

impl WorkerPool[src]

pub fn run(&self, f: impl FnOnce() + Send + 'static) -> Result<(), JsValue>[src]

Executes f in a web worker.

This pool manages a set of web workers to draw from, and f will be spawned quickly into one if the worker is idle. If no idle workers are available then a new web worker will be spawned.

Once f returns the worker assigned to f is automatically reclaimed by this WorkerPool. This method provides no method of learning when f completes, and for that you'll need to use run_notify.

Errors

If an error happens while spawning a web worker or sending a message to a web worker, that error is returned.

pub fn run_notify<T>(
    &self,
    f: impl FnOnce() -> T + Send + 'static
) -> Result<impl Future<Item = T, Error = JsValue> + 'static, JsValue> where
    T: Send + 'static, 
[src]

Executes the closure f in a web worker, returning a future of the value that f produces.

This method is the same as run execept that it allows recovering the return value of the closure f in a nonblocking fashion with the future returned.

Errors

If an error happens while spawning a web worker or sending a message to a web worker, that error is returned.

Trait Implementations

impl From<WorkerPool> for JsValue[src]

impl FromWasmAbi for WorkerPool[src]

type Abi = u32

The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more

impl IntoWasmAbi for WorkerPool[src]

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI boundary. Read more

impl OptionFromWasmAbi for WorkerPool[src]

impl OptionIntoWasmAbi for WorkerPool[src]

impl RefFromWasmAbi for WorkerPool[src]

type Abi = u32

The wasm ABI type references to Self are recovered from.

type Anchor = Ref<'static, WorkerPool>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don't persist beyond one function call, and so that they remain anonymous. Read more

impl RefMutFromWasmAbi for WorkerPool[src]

type Abi = u32

Same as RefFromWasmAbi::Abi

type Anchor = RefMut<'static, WorkerPool>

Same as RefFromWasmAbi::Anchor

impl WasmDescribe for WorkerPool[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ReturnWasmAbi for T where
    T: IntoWasmAbi
[src]

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.