Struct stateful_async_worker::WorkerThread [−][src]
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]
ThreadState: Default + Send + 'static,
Result: Send + 'static,
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]
ThreadState: Send + 'static,
Result: Send + 'static,
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]
F: FnOnce(&mut ThreadState) -> Result + Send + 'static,
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]
&self,
func: Box<dyn FnOnce(&mut ThreadState) -> Result + Send + 'static>
) -> Result
Like work_on
but for functions that are already boxed.
Trait Implementations
impl<ThreadState, Result> Clone for WorkerThread<ThreadState, Result>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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]
Result: Send,
impl<ThreadState, Result> Sync for WorkerThread<ThreadState, Result> where
Result: Send,
[src]
Result: Send,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,