pub struct BackgroundTasks { /* private fields */ }Expand description
A request-scoped handle for scheduling work that runs after the response.
A handler injects it with Extension<BackgroundTasks> and schedules work
anywhere in its body, instead of restructuring its return type around
Background<T>.
A scheduled task is attached to the response dispatch produces whatever the
outcome is, including a rejection, a typed domain error, and an aborted
invocation, so an adapter runs it once the body has been written. This is
the one behavioral difference from Background<T>, whose tasks ride on a
success value and are therefore discarded when the operation fails.
Implementations§
Source§impl BackgroundTasks
impl BackgroundTasks
pub fn new() -> Self
Sourcepub fn add_task(&self, task: BackgroundTask)
pub fn add_task(&self, task: BackgroundTask)
Schedules a prepared task.
Sourcepub fn add<Task, TaskFuture>(&self, task: Task)where
Task: FnOnce() -> TaskFuture + 'static,
TaskFuture: Future<Output = Result<(), BackgroundTaskError>> + 'static,
pub fn add<Task, TaskFuture>(&self, task: Task)where
Task: FnOnce() -> TaskFuture + 'static,
TaskFuture: Future<Output = Result<(), BackgroundTaskError>> + 'static,
Schedules a fallible after-response task.
Sourcepub fn add_infallible<Task, TaskFuture>(&self, task: Task)
pub fn add_infallible<Task, TaskFuture>(&self, task: Task)
Schedules an after-response task that cannot fail.
Sourcepub fn take(&self) -> Vec<BackgroundTask>
pub fn take(&self) -> Vec<BackgroundTask>
Takes the scheduled tasks, leaving the handle empty.
Trait Implementations§
Source§impl Clone for BackgroundTasks
impl Clone for BackgroundTasks
Source§fn clone(&self) -> BackgroundTasks
fn clone(&self) -> BackgroundTasks
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more