pub struct ThreadPerTaskExecutor { /* private fields */ }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 TrackedTask that can be used to wait for the result.
§Semantics
- One task, one thread — each
Executor::callorExecutor::executespawns a new OS thread. There is no pool and no submission queue. - Blocking or async wait —
TrackedTask::getblocks the calling thread, while awaiting the handle uses a waker and does not block the polling thread. - Completion probe —
TrackedTask::is_donereads the terminal task state; result publication to the handle may still be racing with that observation (you still needTrackedTask::getfor the value).
§Examples
use std::io;
use qubit_executor::{Executor, ThreadPerTaskExecutor};
let executor = ThreadPerTaskExecutor::new();
let handle = executor
.call(|| Ok::<i32, io::Error>(40 + 2))
.expect("worker thread should spawn");
// Blocks the current thread until the spawned thread completes.
let value = handle.get().expect("task should succeed");
assert_eq!(value, 42);Implementations§
Source§impl ThreadPerTaskExecutor
impl ThreadPerTaskExecutor
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an executor using the platform default worker stack size.
§Returns
A thread-per-task executor with default worker thread configuration.
Sourcepub fn builder() -> ThreadPerTaskExecutorBuilder
pub fn builder() -> ThreadPerTaskExecutorBuilder
Creates a builder for configuring this executor.
§Returns
A builder initialized with default worker thread options.
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for ThreadPerTaskExecutor
impl Default for ThreadPerTaskExecutor
Source§impl Executor for ThreadPerTaskExecutor
impl Executor for ThreadPerTaskExecutor
Source§fn call<C, R, E>(&self, task: C) -> Result<TrackedTask<R, E>, SubmissionError>
fn call<C, R, E>(&self, task: C) -> Result<TrackedTask<R, E>, SubmissionError>
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 TrackedTask that can block or await the spawned task’s final
result.
§Errors
Returns SubmissionError::WorkerSpawnFailed if the worker thread
cannot be created.
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