pub fn sleep(duration: Duration) -> impl Future<Output = ()> + SendExpand description
Waits duration without using CPU (JavaScript’s setTimeout): pacing for sse streams and polling.
On Workers, time spent waiting is not CPU time: the free plan’s 10 ms
per request only counts the work between waits. An HTTP request may wait
as long as its client stays connected; a queue or scheduled invocation
is limited to 15 minutes of wall time. The returned future is Send, so
it can be awaited in handlers and in sse::stream
steps. Only runs on Workers (natively it panics, like every binding).
§Examples
use std::time::Duration;
async fn slow() -> &'static str {
ocre::sleep(Duration::from_millis(500)).await;
"done"
}