pub struct Injector<S> { /* private fields */ }
Expand description
An injector queue for spawning tasks on multiple Scheduler
instances.
Implementations§
Source§impl<S: Schedule> Injector<S>
impl<S: Schedule> Injector<S>
Sourcepub const unsafe fn new_with_static_stub(stub: &'static TaskStub) -> Self
pub const unsafe fn new_with_static_stub(stub: &'static TaskStub) -> Self
Returns a new injector queue.
§Safety
The “stub” provided must ONLY EVER be used for a single
Injector
instance. Re-using the stub for multiple distributors
or schedulers may lead to undefined behavior.
Sourcepub fn spawn_allocated<STO, F>(
&self,
task: STO::StoredTask,
) -> JoinHandle<F::Output> ⓘ
pub fn spawn_allocated<STO, F>( &self, task: STO::StoredTask, ) -> JoinHandle<F::Output> ⓘ
Spawns a pre-allocated task on the injector queue.
The spawned task will be executed by any
Scheduler
/StaticScheduler
instance that runs tasks from this
queue.
This method is used to spawn a task that requires some bespoke
procedure of allocation, typically of a custom Storage
implementor.
See the documentation for the Storage
trait for more details on
using custom task storage.
When the “alloc” feature flag is available, tasks that do not require
custom storage may be spawned using the Injector::spawn
method,
instead.
This method returns a JoinHandle
that can be used to await the
task’s output. Dropping the JoinHandle
detaches the spawned task,
allowing it to run in the background without awaiting its output.
Sourcepub fn try_steal(&self) -> Result<Stealer<'_, S>, TryStealError>
pub fn try_steal(&self) -> Result<Stealer<'_, S>, TryStealError>
Attempt to take tasks from the injector queue.
§Returns
Ok(
Stealer
`)) if tasks can be spawned from the injector queue.Err
(TryStealError::Empty
)
if there were no tasks in this injector queue.Err
(TryStealError::Busy
)
if another worker was already taking tasks from this injector queue.
Source§impl<S: Schedule> Injector<S>
impl<S: Schedule> Injector<S>
Sourcepub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
Spawns a new task on the injector queue, to execute on any
Scheduler
/StaticScheduler
instance that runs tasks from this
queue.
This method returns a JoinHandle
that can be used to await the
task’s output. Dropping the JoinHandle
detaches the spawned task,
allowing it to run in the background without awaiting its output.