Struct cfx_tasks::TaskExecutor
source · 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
].