pub struct BackgroundExecutor { /* private fields */ }Expand description
A pointer to the executor that is currently running, for spawning background tasks.
Implementations§
Source§impl BackgroundExecutor
impl BackgroundExecutor
Sourcepub fn new(dispatcher: Arc<dyn PlatformDispatcher>) -> Self
pub fn new(dispatcher: Arc<dyn PlatformDispatcher>) -> Self
Creates a new BackgroundExecutor from the given PlatformDispatcher.
Sourcepub fn scheduler_executor(&self) -> BackgroundExecutor
pub fn scheduler_executor(&self) -> BackgroundExecutor
Returns the underlying scheduler::BackgroundExecutor.
This is used by Ex to pass the executor to thread/worktree code.
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 with the given priority.
When Priority::RealtimeAudio is used, the task runs on a dedicated thread with
realtime scheduling priority, suitable for audio processing.
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 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 (const: unstable) · 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 UnsafeUnpin 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> 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