pub struct BackgroundExecutor { /* private fields */ }Expand description
An executor that runs Send futures on the background thread pool.
Applications get one from background_executor on their context. Cloning
is cheap, and every clone shares the same scheduler.
Implementations§
Source§impl BackgroundExecutor
impl BackgroundExecutor
Sourcepub fn new(scheduler: Arc<dyn Scheduler>) -> Self
pub fn new(scheduler: Arc<dyn Scheduler>) -> Self
Creates a background executor that spawns onto scheduler.
Sourcepub fn spawn<F>(&self, future: F) -> Task<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> Task<F::Output> ⓘ
Spawns a future on the background thread pool with the default priority.
The future may run on any background thread, so it must be Send. Dropping
the returned Task cancels the future. Call Task::detach to let
it finish on its own. Use LocalExecutor::spawn for futures that
aren’t Send or that need to stay on the main thread.
Sourcepub fn spawn_with_priority<F>(
&self,
priority: Priority,
future: F,
) -> Task<F::Output> ⓘ
pub fn spawn_with_priority<F>( &self, priority: Priority, future: F, ) -> Task<F::Output> ⓘ
Spawns a future on the background thread pool at priority.
Like Self::spawn, but the scheduler uses priority to order this
future against other background work waiting to run.
Sourcepub fn spawn_realtime<F>(&self, future: F) -> Task<F::Output> ⓘ
pub fn spawn_realtime<F>(&self, future: F) -> Task<F::Output> ⓘ
Spawns a future on the platform’s realtime thread, for latency-sensitive work such as audio processing.
The future must be Send. Use Self::spawn for everything else.
Sourcepub fn timer(&self, duration: Duration) -> Timer ⓘ
pub fn timer(&self, duration: Duration) -> Timer ⓘ
Returns a Timer that completes after duration.
Sourcepub fn now(&self) -> Instant
pub fn now(&self) -> Instant
Returns the current time from this scheduler’s clock.
Under the test scheduler this is the simulated clock, which moves only when the test advances it.
Sourcepub fn scheduler(&self) -> &Arc<dyn Scheduler> ⓘ
pub fn scheduler(&self) -> &Arc<dyn Scheduler> ⓘ
Returns the scheduler that this executor spawns onto.
Sourcepub fn spawn_dedicated<F, Fut>(&self, f: F) -> Task<Fut::Output> ⓘ
pub fn spawn_dedicated<F, Fut>(&self, f: F) -> Task<Fut::Output> ⓘ
Spawns a closure on a new session that has its own LocalExecutor.
The closure runs on a new OS thread under the platform scheduler, or on
the test scheduler’s loop under TestScheduler. Its future can use
the executor it receives to spawn more work on that thread.
The returned task is the closure’s work. Dropping it cancels the work,
awaiting it yields the closure’s return value, and Task::detach
lets the work run on after the caller is done with it.