Provides async sleep_for
and sleep_until
functions.
This crate 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 executorstable
requires the feature once_cell
.
This uses once_cell
crate
which contains some unsafe code.
This is necessary until
std::lazy::OnceCell
is stable.rust
safina_timer::start_timer_thread();
let duration = Duration::from_secs(10);
safina_timer::sleep_for(duration).await;
rust
safina_timer::start_timer_thread();
let deadline =
Instant::now() + Duration::from_secs(1);
safina_timer::sleep_until(deadline).await;
rust
safina_timer::start_timer_thread();
let deadline =
Instant::now() + Duration::from_secs(1);
let req = safina_timer::with_deadline(
read_request(), deadline).await??;
let data = safina_timer::with_deadline(
read_data(req), deadline).await??;
safina_timer::with_deadline(
write_data(data), deadline ).await??;
safina_timer::with_deadline(
send_response(data), deadline).await??;
rust
safina_timer::start_timer_thread();
let req = safina_timer::with_timeout(
read_request(), Duration::from_secs(1)
).await??;
let data = safina_timer::with_timeout(
read_data(req), Duration::from_secs(2)
).await??;
safina_timer::with_timeout(
write_data(data), Duration::from_secs(2)
).await??;
safina_timer::with_timeout(
send_response(data),
Duration::from_secs(1)
).await??;
unsafe
codestd::thread::park_timeout
as its source of timeunsafe
no_std
bare_metal
once_cell
.safina-async-test
changesBox::pin
.with_deadline
and with_timeout
:TimerThreadNotStarted
error and
return new 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
once_cell
.FnOnce
structs).Cargo.toml
and bump version number../release.sh
License: Apache-2.0