This is a safe Rust library providing async sleep_for
and sleep_until
functions.
These functions return futures that complete at the specified time.
It is part of safina
, a safe async runtime.
forbid(unsafe_code)
std
std::thread::park_timeout
via
std::sync::mpsc::Receiver::recv_timeout
.safina-executor
or any async executornightly
, for OnceCellrust
safina_timer::start_timer_thread();
safina_timer::sleep_for(Duration::from_secs(10)).await;
rust
safina_timer::start_timer_thread();
let deadline =
Instant::now() + Duration::from_millis(500);
safina_timer::sleep_until(deadline).await;
rust
use safina_timer::with_deadline;
safina_timer::start_timer_thread();
let deadline =
Instant::now() + Duration::from_millis(500);
let req =
with_deadline(read_request(), deadline).await??;
let data =
with_deadline(read_data(req), deadline).await??;
with_deadline(write_data(data), deadline).await??;
with_deadline(send_response(data), deadline).await??;
rust
use safina_timer::with_timeout;
safina_timer::start_timer_thread();
let req = with_timeout(
read_request(), Duration::from_millis(500)
).await??;
let data = with_timeout(
read_data(req), Duration::from_millis(1000)
).await??;
with_timeout(
write_data(data), Duration::from_millis(1000)
).await??;
with_timeout(
send_response(data), Duration::from_millis(5000)
).await??;
https://docs.rs/safina-timer
unsafe
codestd::thread::park_timeout
as its source of timeunsafe
Cargo.toml
and bump version number../release.sh
with_deadline
and with_timeout
:DeadlineExceeded
struct instead of DeadlineError enum.
This allows callers to write a match clause like Err(DeadlineExceeded)
.std::boxed::Box::pin
so callers don't have to.sleep_until
and sleep_for
return ()
and
panic if start_timer_thread()
has not been called.SleepFuture::poll
, as required by the
std::future::Future::poll
contract.with_deadline
and with_timeout
functions.sleep_until
sleep_for
License: Apache-2.0