Crates.io | safina-timer |
lib.rs | safina-timer |
version | 0.1.13 |
source | src |
created_at | 2020-12-01 07:27:48.93338 |
updated_at | 2024-10-27 23:42:58.243869 |
description | Safe async timers - ARCHIVED: Code moved to `safina` crate. |
homepage | |
repository | https://gitlab.com/leonhard-llc/safina-rs |
max_upload_size | |
id | 318490 |
size | 40,954 |
This crate is archived and will not be updated.
The code is now at
safina::timer
in the
safina
crate.
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.safina_timer::start_timer_thread();
let duration = Duration::from_secs(10);
safina_timer::sleep_for(duration).await;
safina_timer::start_timer_thread();
let deadline =
Instant::now() + Duration::from_secs(1);
safina_timer::sleep_until(deadline).await;
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??;
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
safina-executor
v0.2.0.once_cell
.Box::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.FnOnce
structs).Cargo.toml
and bump version number../release.sh