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§
Source§impl 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)
pub fn spawn_ok<Fut>(&self, future: Fut)
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
pub fn spawn<Fut>( &self, future: Fut, ) -> impl Future<Output = Result<Fut::Output, Canceled>> + '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§
Source§impl Clone for ThreadPool
impl Clone for ThreadPool
Source§impl Drop for ThreadPool
impl Drop for ThreadPool
Source§impl From<ThreadPool> for JsValue
impl From<ThreadPool> for JsValue
Source§fn from(value: ThreadPool) -> Self
fn from(value: ThreadPool) -> Self
Source§impl FromWasmAbi for ThreadPool
impl FromWasmAbi for ThreadPool
Source§impl IntoWasmAbi for ThreadPool
impl IntoWasmAbi for ThreadPool
Source§impl LongRefFromWasmAbi for ThreadPool
impl LongRefFromWasmAbi for ThreadPool
Source§impl OptionFromWasmAbi for ThreadPool
impl OptionFromWasmAbi for ThreadPool
Source§impl OptionIntoWasmAbi for ThreadPool
impl OptionIntoWasmAbi for ThreadPool
Source§impl RefFromWasmAbi for ThreadPool
impl RefFromWasmAbi for ThreadPool
Source§type Anchor = RcRef<ThreadPool>
type Anchor = RcRef<ThreadPool>
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.Source§impl RefMutFromWasmAbi for ThreadPool
impl RefMutFromWasmAbi for ThreadPool
Source§impl TryFromJsValue for ThreadPool
impl TryFromJsValue for ThreadPool
Source§impl VectorFromWasmAbi for ThreadPool
impl VectorFromWasmAbi for ThreadPool
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[ThreadPool]>
Source§impl VectorIntoJsValue for ThreadPool
impl VectorIntoJsValue for ThreadPool
fn vector_into_jsvalue(vector: Box<[ThreadPool]>) -> JsValue
Source§impl VectorIntoWasmAbi for ThreadPool
impl VectorIntoWasmAbi for ThreadPool
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[ThreadPool]>) -> Self::Abi
Source§impl WasmDescribeVector for ThreadPool
impl WasmDescribeVector for ThreadPool
impl SupportsConstructor for ThreadPool
impl SupportsInstanceProperty for ThreadPool
impl SupportsStaticProperty for ThreadPool
Auto Trait Implementations§
impl Freeze for ThreadPool
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
Source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.