Struct wasm_futures_executor::ThreadPool
source · [−]pub struct ThreadPool { /* private fields */ }
Expand description
A general-purpose thread pool for scheduling tasks that poll futures to completion.
The thread pool multiplexes any number of tasks onto a fixed number of worker threads.
This type is a clonable handle to the threadpool itself. Cloning it will only create a new reference, not a new threadpool.
The API follows futures_executor::ThreadPool
.
Implementations
sourceimpl ThreadPool
impl ThreadPool
sourcepub async fn new(size: usize) -> Result<ThreadPool, JsValue>
pub async fn new(size: usize) -> Result<ThreadPool, JsValue>
Creates a new ThreadPool
with the provided count of web workers. The returned future
will resolve after all workers have spawned and are ready to accept work.
sourcepub async fn max_threads() -> Result<Self, JsValue>
pub async fn max_threads() -> Result<Self, JsValue>
Creates a new ThreadPool
with Navigator.hardwareConcurrency
web workers.
sourcepub fn spawn_ok<Fut>(&self, future: Fut) where
Fut: Future<Output = ()> + Send + 'static,
pub fn spawn_ok<Fut>(&self, future: Fut) where
Fut: Future<Output = ()> + Send + 'static,
Spawns a task that polls the given future with output ()
to
completion.
use wasm_futures_executor::ThreadPool;
let pool = ThreadPool::new().await.unwrap();
let future = async { /* ... */ };
pool.spawn_ok(future);
sourcepub fn spawn<Fut>(
&self,
future: Fut
) -> impl Future<Output = Result<Fut::Output, Canceled>> + 'static where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
pub fn spawn<Fut>(
&self,
future: Fut
) -> impl Future<Output = Result<Fut::Output, Canceled>> + 'static where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
Spawns a task. This function returns a future which eventually resolves to the output of the computation. Note: The provided future is polled on the thread pool, no matter whether the returned future is polled or not.
Trait Implementations
sourceimpl Clone for ThreadPool
impl Clone for ThreadPool
sourceimpl Drop for ThreadPool
impl Drop for ThreadPool
sourceimpl From<ThreadPool> for JsValue
impl From<ThreadPool> for JsValue
sourcefn from(value: ThreadPool) -> Self
fn from(value: ThreadPool) -> Self
Converts to this type from the input type.
sourceimpl FromWasmAbi for ThreadPool
impl FromWasmAbi for ThreadPool
sourceimpl IntoWasmAbi for ThreadPool
impl IntoWasmAbi for ThreadPool
sourceimpl OptionFromWasmAbi for ThreadPool
impl OptionFromWasmAbi for ThreadPool
sourceimpl OptionIntoWasmAbi for ThreadPool
impl OptionIntoWasmAbi for ThreadPool
sourceimpl RefFromWasmAbi for ThreadPool
impl RefFromWasmAbi for ThreadPool
type Anchor = Ref<'static, ThreadPool>
type Anchor = Ref<'static, ThreadPool>
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
sourceunsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
Recover a Self::Anchor
from Self::Abi
. Read more
sourceimpl RefMutFromWasmAbi for ThreadPool
impl RefMutFromWasmAbi for ThreadPool
type Anchor = RefMut<'static, ThreadPool>
type Anchor = RefMut<'static, ThreadPool>
Same as RefFromWasmAbi::Anchor
sourceunsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
Same as RefFromWasmAbi::ref_from_abi
sourceimpl WasmDescribe for ThreadPool
impl WasmDescribe for ThreadPool
Auto Trait Implementations
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as IntoWasmAbi::Abi
sourcefn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more