pub struct Thread(/* private fields */);Expand description
A representation of a JavaScript thread (Web worker with shared memory).
Implementations§
Source§impl Thread
impl Thread
Sourcepub fn run<Context: Post, F: Future<Output: Post> + 'static>(
&self,
context: Context,
code: impl FnOnce(Context) -> F + Send + 'static,
) -> Task<F::Output> ⓘ
pub fn run<Context: Post, F: Future<Output: Post> + 'static>( &self, context: Context, code: impl FnOnce(Context) -> F + Send + 'static, ) -> Task<F::Output> ⓘ
Execute a function on a thread.
The function will begin executing immediately. The resulting
Task can be awaited to retrieve the result.
§Arguments
§context
A Postable context that will be sent across the thread
boundary using postMessage and passed to the function on the
other side.
§code
A FnOnce implementation containing the code in question.
The function is async, but will run on a Worker so may block
(though doing so will block the thread!). The function itself
must be Send, and Send values can be sent through in its
closure, but once executed the resulting Future will not
be moved, so needn’t be Send.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Thread
impl RefUnwindSafe for Thread
impl !Send for Thread
impl !Sync for Thread
impl Unpin for Thread
impl UnwindSafe for Thread
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
Mutably borrows from an owned value. Read more