cratefield_core/ports/defer.rs
1//! The `Defer` port (architecture section 5, ADR 0007): work that outlives
2//! the response. Request-scoped; travels inside [`crate::Scope`], never in
3//! shared state.
4
5use futures_core::future::BoxFuture;
6
7pub trait Defer: Send + Sync {
8 /// Schedule work to continue after the response is returned
9 /// (`Context::wait_until` on Workers, `tokio::spawn` natively).
10 fn wait_until(&self, fut: BoxFuture<'static, ()>);
11}
12
13/// Drops deferred futures with a warning. Used when no runtime defer is
14/// available; tests that assert on deferred work supply their own.
15#[derive(Debug, Clone, Copy, Default)]
16pub struct NoopDefer;
17
18impl Defer for NoopDefer {
19 fn wait_until(&self, fut: BoxFuture<'static, ()>) {
20 tracing::warn!("deferred work dropped: no Defer port configured");
21 drop(fut);
22 }
23}