I used this example mostly when testing how CLOCK_REALTIME interacts with
suspending the system and alike. I figure it can be useful for this kind of
testing.
---
Cargo.toml | 4 ++++examples/wait_for.rs | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 examples/wait_for.rs
diff --git a/Cargo.toml b/Cargo.toml
index 6bdf2b5..5ffa1d2 100644
--- a/Cargo.toml+++ b/Cargo.toml
@@ -13,3 +13,7 @@ libc = "0.2.126"
chrono = "0.4.19"
thiserror = "1.0.31"
errno = "0.2.8"
++[dev-dependencies]+# Examples use extra features.+tokio = { version = "1", features = ["signal", "rt", "macros", "rt-multi-thread", "time"] }
diff --git a/examples/wait_for.rs b/examples/wait_for.rs
new file mode 100644
index 0000000..52d45aa
--- /dev/null+++ b/examples/wait_for.rs
@@ -0,0 +1,20 @@
+use chrono::Duration;+use chrono::Utc;++/// Takes a number as input and waits that many seconds before exiting.+///+/// Runnable with `cargo run --example=wait_for -- 2`.+#[tokio::main]+async fn main() {+ let mut arguments = std::env::args();+ arguments.next().expect("process executable has a name");+ let arg1 = arguments.next().expect("first argument is specified");++ let duration: i64 = arg1.parse().expect("first argument is a valid integer");+ let duration = Duration::seconds(duration);++ let timeout = Utc::now() + duration;+ tokio_walltime::sleep_until(timeout)+ .await+ .expect("timer completes okay");+}
--
2.39.1