Skip to main content

TaskSpawner

Struct TaskSpawner 

Source
pub struct TaskSpawner<T: Send + 'static> { /* private fields */ }
Expand description

A cheap-to-clone handle for scheduling background tasks onto the shared pool. Held by the shell and handed to the plugin through InitContext, ProcessContext, and the editor’s PluginContext.

A spawner built with Self::new may run its handler concurrently with itself for one instance (see the module’s Concurrency section); Self::new_serialized runs it one at a time.

Implementations§

Source§

impl<T: Send + 'static> TaskSpawner<T>

Source

pub fn new(run: impl Fn(T) + Send + Sync + 'static) -> Self

Register an instance’s handler with the shared pool. run is the monomorphized move |task| task.run(&params), built once by the shell. The pool itself is not started until the first task is actually scheduled, so constructing a spawner for a plugin that never schedules costs only the (small) inbound queue.

The handler may run concurrently with itself for one instance; use Self::new_serialized for a handler that isn’t reentrancy-safe.

Source

pub fn new_serialized(run: impl Fn(T) + Send + Sync + 'static) -> Self

Like Self::new, but the pool runs the handler for a given instance one at a time (“one-slot” mode). The shell selects this when the plugin’s BackgroundTask::SERIALIZED is true.

Source

pub fn try_spawn(&self, task: T) -> Result<(), T>

Enqueue a task, running it on the pool as soon as a worker is free. Wait-free. Returns Err(task) if the inbound queue is full (the audio thread decides what to do - drop, or coalesce via Self::spawn_coalescing - rather than block).

§Errors

Returns the task back when the preallocated inbound queue is full.

Source

pub fn spawn_coalescing(&self, task: T)

Post a task into the single coalescing slot, replacing any still-unrun target. Wait-free, never rejects. Only the newest survives and the worker runs it at most once per drain, so a knob sweep that outruns the handler collapses to one execution, not one build per intermediate target. The displaced target drops on the caller (the audio thread on the hot path), so a coalescing task type should be cheap to drop - a small Copy request, not an owned buffer.

Trait Implementations§

Source§

impl<T: Send + 'static> Clone for TaskSpawner<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for TaskSpawner<T>

§

impl<T> !UnwindSafe for TaskSpawner<T>

§

impl<T> Freeze for TaskSpawner<T>

§

impl<T> Send for TaskSpawner<T>

§

impl<T> Sync for TaskSpawner<T>

§

impl<T> Unpin for TaskSpawner<T>

§

impl<T> UnsafeUnpin for TaskSpawner<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.