pub struct TaskExecutor { /* private fields */ }
Expand description
A type that can spawn new tokio tasks
Implementations§
Source§impl TaskExecutor
impl TaskExecutor
Sourcepub const fn on_shutdown_signal(&self) -> &Shutdown ⓘ
pub const fn on_shutdown_signal(&self) -> &Shutdown ⓘ
Returns the receiver of the shutdown signal.
Sourcepub fn spawn<F>(&self, fut: F) -> JoinHandle<()>
pub fn spawn<F>(&self, fut: F) -> JoinHandle<()>
Spawns the task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
See also [Handle::spawn
].
Sourcepub fn spawn_blocking<F>(&self, fut: F) -> JoinHandle<()>
pub fn spawn_blocking<F>(&self, fut: F) -> JoinHandle<()>
Spawns a blocking task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
See also [Handle::spawn_blocking
].
Sourcepub fn spawn_with_signal<F>(
&self,
f: impl FnOnce(Shutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_with_signal<F>( &self, f: impl FnOnce(Shutdown) -> F, ) -> JoinHandle<()>
Spawns the task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
See also [Handle::spawn
].
Sourcepub fn spawn_critical_blocking<F>(
&self,
name: &'static str,
fut: F,
) -> JoinHandle<()>
pub fn spawn_critical_blocking<F>( &self, name: &'static str, fut: F, ) -> JoinHandle<()>
This spawns a critical blocking task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
If this task panics, the TaskManager
is notified.
Sourcepub fn spawn_critical<F>(&self, name: &'static str, fut: F) -> JoinHandle<()>
pub fn spawn_critical<F>(&self, name: &'static str, fut: F) -> JoinHandle<()>
This spawns a critical task onto the runtime. The given future resolves as soon as the Shutdown signal is received.
If this task panics, the TaskManager
is notified.
Sourcepub fn spawn_critical_with_shutdown_signal<F>(
&self,
name: &'static str,
f: impl FnOnce(Shutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_critical_with_shutdown_signal<F>( &self, name: &'static str, f: impl FnOnce(Shutdown) -> F, ) -> JoinHandle<()>
This spawns a critical task onto the runtime.
If this task panics, the TaskManager
is notified.
Sourcepub fn spawn_critical_with_graceful_shutdown_signal<F>(
&self,
name: &'static str,
f: impl FnOnce(GracefulShutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_critical_with_graceful_shutdown_signal<F>( &self, name: &'static str, f: impl FnOnce(GracefulShutdown) -> F, ) -> JoinHandle<()>
This spawns a critical task onto the runtime.
If this task panics, the TaskManager
is notified.
The TaskManager
will wait until the given future has completed before shutting down.
§Example
executor.spawn_critical_with_graceful_shutdown_signal("grace", |shutdown| async move {
// await the shutdown signal
let guard = shutdown.await;
// do work before exiting the program
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
// allow graceful shutdown
drop(guard);
});
Sourcepub fn spawn_with_graceful_shutdown_signal<F>(
&self,
f: impl FnOnce(GracefulShutdown) -> F,
) -> JoinHandle<()>
pub fn spawn_with_graceful_shutdown_signal<F>( &self, f: impl FnOnce(GracefulShutdown) -> F, ) -> JoinHandle<()>
This spawns a regular task onto the runtime.
The TaskManager
will wait until the given future has completed before shutting down.
§Example
executor.spawn_with_graceful_shutdown_signal(|shutdown| async move {
// await the shutdown signal
let guard = shutdown.await;
// do work before exiting the program
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
// allow graceful shutdown
drop(guard);
});
Trait Implementations§
Source§impl Clone for TaskExecutor
impl Clone for TaskExecutor
Source§fn clone(&self) -> TaskExecutor
fn clone(&self) -> TaskExecutor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TaskExecutor
impl Debug for TaskExecutor
Source§impl TaskSpawner for TaskExecutor
impl TaskSpawner for TaskExecutor
Source§fn spawn(&self, fut: BoxFuture<'static, ()>) -> JoinHandle<()>
fn spawn(&self, fut: BoxFuture<'static, ()>) -> JoinHandle<()>
Handle::spawn
].Source§fn spawn_critical(
&self,
name: &'static str,
fut: BoxFuture<'static, ()>,
) -> JoinHandle<()>
fn spawn_critical( &self, name: &'static str, fut: BoxFuture<'static, ()>, ) -> JoinHandle<()>
Source§fn spawn_blocking(&self, fut: BoxFuture<'static, ()>) -> JoinHandle<()>
fn spawn_blocking(&self, fut: BoxFuture<'static, ()>) -> JoinHandle<()>
Source§impl TaskSpawnerExt for TaskExecutor
impl TaskSpawnerExt for TaskExecutor
Source§fn spawn_critical_with_graceful_shutdown_signal<F>(
&self,
name: &'static str,
f: impl FnOnce(GracefulShutdown) -> F,
) -> JoinHandle<()>
fn spawn_critical_with_graceful_shutdown_signal<F>( &self, name: &'static str, f: impl FnOnce(GracefulShutdown) -> F, ) -> JoinHandle<()>
Source§fn spawn_with_graceful_shutdown_signal<F>(
&self,
f: impl FnOnce(GracefulShutdown) -> F,
) -> JoinHandle<()>
fn spawn_with_graceful_shutdown_signal<F>( &self, f: impl FnOnce(GracefulShutdown) -> F, ) -> JoinHandle<()>
Auto Trait Implementations§
impl Freeze for TaskExecutor
impl !RefUnwindSafe for TaskExecutor
impl Send for TaskExecutor
impl Sync for TaskExecutor
impl Unpin for TaskExecutor
impl !UnwindSafe for TaskExecutor
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 112 bytes