cratefield_runtime_native/ports/defer.rs
1//! `Defer` over `tokio::spawn` (architecture section 5): work that
2//! outlives the response, the native counterpart of
3//! `worker::Context::wait_until`.
4
5use cratefield_core::Defer;
6use futures_core::future::BoxFuture;
7
8/// Spawns deferred work on the tokio runtime. Request-scoped through the
9/// [`Scope`](cratefield_core::Scope) like every defer — the runtime holds
10/// no state of its own.
11///
12/// The spawned task is detached: a panic inside it is tokio's default
13/// panic-and-drop (the join handle is not awaited, exactly like a
14/// fire-and-forget `wait_until` on Workers). Handlers that need errors
15/// observed do the observing themselves before deferring.
16#[derive(Debug, Clone, Copy, Default)]
17pub struct SpawnDefer;
18
19impl Defer for SpawnDefer {
20 fn wait_until(&self, fut: BoxFuture<'static, ()>) {
21 tokio::spawn(fut);
22 }
23}