pub struct ThreadPerTaskExecutor;Expand description
Executes each task on a dedicated OS thread.
This executor does not manage lifecycle or maintain a queue. Each accepted
task receives a TaskHandle that can be used to wait for the result.
§Semantics
- One task, one thread — each
Executor::callorExecutor::executespawns a newstd::thread::spawnworker. There is no pool and no submission queue. - Blocking or async wait —
TaskHandle::getblocks the calling thread, while awaiting the handle uses a waker and does not block the polling thread. - Completion probe —
TaskHandle::is_donereads an atomic flag set after the worker publishes the result; it does not retrieve the value (you still needTaskHandle::getfor that).
§Examples
use std::io;
use qubit_executor::executor::{
Executor,
ThreadPerTaskExecutor,
};
let executor = ThreadPerTaskExecutor;
let handle = executor.call(|| Ok::<i32, io::Error>(40 + 2));
// Blocks the current thread until the spawned thread completes.
let value = handle.get().expect("task should succeed");
assert_eq!(value, 42);Trait Implementations§
Source§impl Clone for ThreadPerTaskExecutor
impl Clone for ThreadPerTaskExecutor
Source§fn clone(&self) -> ThreadPerTaskExecutor
fn clone(&self) -> ThreadPerTaskExecutor
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ThreadPerTaskExecutor
impl Debug for ThreadPerTaskExecutor
Source§impl Default for ThreadPerTaskExecutor
impl Default for ThreadPerTaskExecutor
Source§fn default() -> ThreadPerTaskExecutor
fn default() -> ThreadPerTaskExecutor
Returns the “default value” for a type. Read more
Source§impl Executor for ThreadPerTaskExecutor
impl Executor for ThreadPerTaskExecutor
Source§fn call<C, R, E>(&self, task: C) -> Self::Execution<R, E>
fn call<C, R, E>(&self, task: C) -> Self::Execution<R, E>
Spawns one OS thread for the callable and returns a handle to its result.
§Parameters
task- Callable to run on a dedicated OS thread.
§Returns
A TaskHandle that can block or await the spawned task’s final
result.
impl Copy for ThreadPerTaskExecutor
Auto Trait Implementations§
impl Freeze for ThreadPerTaskExecutor
impl RefUnwindSafe for ThreadPerTaskExecutor
impl Send for ThreadPerTaskExecutor
impl Sync for ThreadPerTaskExecutor
impl Unpin for ThreadPerTaskExecutor
impl UnsafeUnpin for ThreadPerTaskExecutor
impl UnwindSafe for ThreadPerTaskExecutor
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