Struct maitake::scheduler::Injector

source ·
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>

source

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.

source

pub fn spawn_allocated<STO, F>( &self, task: STO::StoredTask, ) -> JoinHandle<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static, STO: Storage<S, F>,

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.

source

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>

source

pub fn new() -> Self

Available on crate feature alloc only.

Returns a new Injector queue with a dynamically heap-allocated TaskStub.

source

pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static,

Available on crate feature alloc only.

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.

Trait Implementations§

source§

impl<S> Debug for Injector<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S: Schedule> Default for Injector<S>

Available on crate feature alloc only.
source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for Injector<S>

§

impl<S> !RefUnwindSafe for Injector<S>

§

impl<S> Send for Injector<S>

§

impl<S> Sync for Injector<S>

§

impl<S> Unpin for Injector<S>

§

impl<S> !UnwindSafe for Injector<S>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more