Struct stateful_async_worker::WorkerThread[][src]

pub struct WorkerThread<ThreadState, Result> { /* fields omitted */ }

Abstracts a stateful background worker thread, that can run synchronous functions and provide the return value as asynchronous future.

The thread owns an arbitrary ThreadState, which will be passed as a mutable reference to the called function. Thus the asynchronous code can easily access and mutate state when necessary. The worker will only process a single function at a time.

Implementations

impl<ThreadState, Result> WorkerThread<ThreadState, Result> where
    ThreadState: Default + Send + 'static,
    Result: Send + 'static, 
[src]

pub fn spawn() -> Self[src]

Spawns a new worker thread. The state will be initialized with Default::default().

impl<ThreadState, Result> WorkerThread<ThreadState, Result> where
    ThreadState: Send + 'static,
    Result: Send + 'static, 
[src]

pub fn spawn_with(data: ThreadState) -> Self[src]

Spawns a new worker thread. The state will be initialized with data.

pub async fn work_on<F>(&self, func: F) -> Result where
    F: FnOnce(&mut ThreadState) -> Result + Send + 'static, 
[src]

Pass a synchronous function, so the worker thread can execute it. Execution will be begin even before the first call to poll.

pub async fn work_on_boxed(
    &self,
    func: Box<dyn FnOnce(&mut ThreadState) -> Result + Send + 'static>
) -> Result
[src]

Like work_on but for functions that are already boxed.

Trait Implementations

impl<ThreadState, Result> Clone for WorkerThread<ThreadState, Result>[src]

Auto Trait Implementations

impl<ThreadState, Result> RefUnwindSafe for WorkerThread<ThreadState, Result>[src]

impl<ThreadState, Result> Send for WorkerThread<ThreadState, Result> where
    Result: Send
[src]

impl<ThreadState, Result> Sync for WorkerThread<ThreadState, Result> where
    Result: Send
[src]

impl<ThreadState, Result> Unpin for WorkerThread<ThreadState, Result>[src]

impl<ThreadState, Result> UnwindSafe for WorkerThread<ThreadState, Result>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.