pub struct BackgroundExecutor { /* private fields */ }Expand description
A pointer to the executor that is currently running, for spawning background tasks.
Implementations§
Source§impl BackgroundExecutor
BackgroundExecutor lets you run things on background threads.
In production this is a thread pool with no ordering guarantees.
In tests this is simulated by running tasks one by one in a deterministic
(but arbitrary) order controlled by the SEED environment variable.
impl BackgroundExecutor
BackgroundExecutor lets you run things on background threads.
In production this is a thread pool with no ordering guarantees.
In tests this is simulated by running tasks one by one in a deterministic
(but arbitrary) order controlled by the SEED environment variable.
Sourcepub fn spawn<R>(
&self,
future: impl Future<Output = R> + Send + 'static,
) -> Task<R> ⓘwhere
R: Send + 'static,
pub fn spawn<R>(
&self,
future: impl Future<Output = R> + Send + 'static,
) -> Task<R> ⓘwhere
R: Send + 'static,
Enqueues the given future to be run to completion on a background thread.
Sourcepub fn spawn_with_priority<R>(
&self,
priority: Priority,
future: impl Future<Output = R> + Send + 'static,
) -> Task<R> ⓘwhere
R: Send + 'static,
pub fn spawn_with_priority<R>(
&self,
priority: Priority,
future: impl Future<Output = R> + Send + 'static,
) -> Task<R> ⓘwhere
R: Send + 'static,
Enqueues the given future to be run to completion on a background thread.
Sourcepub async fn await_on_background<R>(
&self,
future: impl Future<Output = R> + Send,
) -> Rwhere
R: Send,
pub async fn await_on_background<R>(
&self,
future: impl Future<Output = R> + Send,
) -> Rwhere
R: Send,
Enqueues the given future to be run to completion on a background thread and blocking the current task on it.
This allows to spawn background work that borrows from its scope. Note that the supplied future will run to completion before the current task is resumed, even if the current task is slated for cancellation.
Sourcepub fn spawn_labeled<R>(
&self,
label: TaskLabel,
future: impl Future<Output = R> + Send + 'static,
) -> Task<R> ⓘwhere
R: Send + 'static,
pub fn spawn_labeled<R>(
&self,
label: TaskLabel,
future: impl Future<Output = R> + Send + 'static,
) -> Task<R> ⓘwhere
R: Send + 'static,
Enqueues the given future to be run to completion on a background thread. The given label can be used to control the priority of the task in tests.
Sourcepub fn block<R>(&self, future: impl Future<Output = R>) -> R
pub fn block<R>(&self, future: impl Future<Output = R>) -> R
Block the current thread until the given future resolves.
Consider using block_with_timeout instead.
Sourcepub fn block_with_timeout<Fut: Future>(
&self,
duration: Duration,
future: Fut,
) -> Result<Fut::Output, impl Future<Output = Fut::Output> + use<Fut>>
pub fn block_with_timeout<Fut: Future>( &self, duration: Duration, future: Fut, ) -> Result<Fut::Output, impl Future<Output = Fut::Output> + use<Fut>>
Block the current thread until the given future resolves
or duration has elapsed.
Sourcepub async fn scoped<'scope, F>(&self, scheduler: F)
pub async fn scoped<'scope, F>(&self, scheduler: F)
Scoped lets you start a number of tasks and waits for all of them to complete before returning.
Sourcepub async fn scoped_priority<'scope, F>(&self, priority: Priority, scheduler: F)
pub async fn scoped_priority<'scope, F>(&self, priority: Priority, scheduler: F)
Scoped lets you start a number of tasks and waits for all of them to complete before returning.
Sourcepub fn now(&self) -> Instant
pub fn now(&self) -> Instant
Get the current time.
Calling this instead of std::time::Instant::now allows the use
of fake timers in tests.
Sourcepub fn timer(&self, duration: Duration) -> Task<()> ⓘ
pub fn timer(&self, duration: Duration) -> Task<()> ⓘ
Returns a task that will complete after the given duration. Depending on other concurrent tasks the elapsed duration may be longer than requested.
Sourcepub fn is_main_thread(&self) -> bool
pub fn is_main_thread(&self) -> bool
Whether we’re on the main thread.
Trait Implementations§
Source§impl Clone for BackgroundExecutor
impl Clone for BackgroundExecutor
Source§fn clone(&self) -> BackgroundExecutor
fn clone(&self) -> BackgroundExecutor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BackgroundExecutor
impl !RefUnwindSafe for BackgroundExecutor
impl Send for BackgroundExecutor
impl Sync for BackgroundExecutor
impl Unpin for BackgroundExecutor
impl !UnwindSafe for BackgroundExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more