pub struct TaskSpawner<T>where
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.
Implementations§
Source§impl<T> TaskSpawner<T>where
T: Send + 'static,
impl<T> TaskSpawner<T>where
T: Send + 'static,
Sourcepub fn new(run: impl Fn(T) + Send + Sync + 'static) -> TaskSpawner<T>
pub fn new(run: impl Fn(T) + Send + Sync + 'static) -> TaskSpawner<T>
Register an instance’s handler with the shared pool. run is the
monomorphized move |task| L::run_task(task, ¶ms), 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.
Sourcepub fn try_spawn(&self, task: T) -> Result<(), T>
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.
Sourcepub fn spawn_coalescing(&self, task: T)
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> Clone for TaskSpawner<T>where
T: Send + 'static,
impl<T> Clone for TaskSpawner<T>where
T: Send + 'static,
Source§fn clone(&self) -> TaskSpawner<T>
fn clone(&self) -> TaskSpawner<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more