Skip to main content

libdd_capabilities/
sleep.rs

1// Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4//! Sleep capability trait.
5//!
6//! Abstracts async sleep so that native code can use `tokio::time::sleep`
7//! while wasm delegates to `setTimeout` via `JsFuture`.
8
9use crate::maybe_send::MaybeSend;
10use core::future::Future;
11use std::time::Duration;
12
13pub trait SleepCapability: Clone + std::fmt::Debug {
14    /// Construct a new sleeper.
15    ///
16    /// Stateless impls return a unit struct; stateful impls (mock clocks,
17    /// virtual time sources, etc.) should return a sensible default. Callers
18    /// that don't have an instance handy can use the static-style
19    /// `C::new().sleep(duration)` pattern, mirroring `HttpClientCapability`'s
20    /// `new_client()` + `request(&self)` shape.
21    fn new() -> Self;
22
23    fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + MaybeSend;
24}