Struct Executor

Source
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>
where T: Send + Sync + 'static,

Source

pub fn new<E, F>(e: E, f: F) -> Self
where F: FnOnce() -> T + Send + 'static, E: Context,

Run f in the Execution context _e, creating an Executor

§Arguments
  • e: The context to run on. For StdContext or RayonGlobalContext you can just use ::default(), they are stateless.
  • f: The function to run. f must be FnOnce + Send + 'static - as if you would pass it to std::thread::spawn
Source

pub fn is_done(&self) -> bool

Returns true if the function passed into Executor::new() has completed

Source

pub fn result(&self) -> Option<Arc<T>>

Returns Some(Arc<T>) if the function passed into Execute::new() has completed, or None otherwise

Source

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>
where T: Sync + Send,

§

impl<T> Sync for Executor<T>
where T: Sync + Send,

§

impl<T> Unpin for Executor<T>

§

impl<T> UnwindSafe for Executor<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.