pub struct Executor<T> { /* private fields */ }
Expand description
An Executor
runs a function in some Context
(this will usually be a thread)
This is similar to std::thread::JoinHandle
, though it always will yield an Arc<T>
instead
This allows the Executor
to be stored itself, and accesses via Executor::result()
are a cheap arc clone instead of requiring moves.
Of course, using Executor::take()
, you can still grab the inner data if its available.
Implementations§
Source§impl<T> Executor<T>
impl<T> Executor<T>
Sourcepub fn new<E, F>(e: E, f: F) -> Self
pub fn new<E, F>(e: E, f: F) -> Self
Run f
in the Execution context _e
, creating an Executor
§Arguments
e
: The context to run on. ForStdContext
orRayonGlobalContext
you can just use::default()
, they are stateless.f
: The function to run.f
must beFnOnce + Send + 'static
- as if you would pass it tostd::thread::spawn
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Returns true if the function passed into Executor::new()
has completed
Sourcepub fn result(&self) -> Option<Arc<T>>
pub fn result(&self) -> Option<Arc<T>>
Returns Some(Arc<T>)
if the function passed into Execute::new()
has completed, or None
otherwise
Sourcepub fn take_result(self) -> Option<T>
pub fn take_result(self) -> Option<T>
Consumes this Executor
, returning either Some(T)
if the executor has completed, or None
if it has not.
There is no way for the work function if you you unsuccessfully tried to take the data. It will run to its end.
There is no way to retrieve this data as well.
So you probably only want to only `Executor::take()` if `Executor::is_done()` returnd true before.
Auto Trait Implementations§
impl<T> Freeze for Executor<T>
impl<T> RefUnwindSafe for Executor<T>
impl<T> Send for Executor<T>
impl<T> Sync for Executor<T>
impl<T> Unpin for Executor<T>
impl<T> UnwindSafe for Executor<T>
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