[−][src]Struct web_worker::WorkerPool
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]
&self,
f: impl FnOnce() -> T + Send + 'static
) -> Result<impl Future<Item = T, Error = JsValue> + 'static, JsValue> where
T: Send + 'static,
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]
fn from(value: WorkerPool) -> Self
[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
unsafe fn from_abi(js: u32) -> Self
[src]
impl IntoWasmAbi for WorkerPool
[src]
type Abi = u32
The wasm ABI type that this converts into when crossing the ABI boundary. Read more
fn into_abi(self) -> u32
[src]
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
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
[src]
impl RefMutFromWasmAbi for WorkerPool
[src]
type Abi = u32
Same as RefFromWasmAbi::Abi
type Anchor = RefMut<'static, WorkerPool>
Same as RefFromWasmAbi::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
[src]
impl WasmDescribe for WorkerPool
[src]
Auto Trait Implementations
impl !RefUnwindSafe for WorkerPool
impl !Send for WorkerPool
impl !Sync for WorkerPool
impl Unpin for WorkerPool
impl !UnwindSafe for WorkerPool
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
[src]
T: IntoWasmAbi,
type Abi = <T as IntoWasmAbi>::Abi
Same as IntoWasmAbi::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,