Skip to main content

linera_kywasmtime/
lib.rs

1pub mod error;
2mod interval;
3mod js;
4mod sleep;
5mod time;
6mod timeout;
7
8/// ```
9/// use std::time::Duration;
10/// use linera_kywasmtime::*;
11///
12/// async fn demo_sleep() {
13///     let duration = Duration::from_millis(500);
14///     sleep(duration).await;
15/// }
16///
17/// async fn demo_sleep_until() {
18///     let deadline = Instant::now() + Duration::from_millis(200);
19///     sleep_until(deadline).await;
20/// }
21///
22/// async fn demo_interval() {
23///     let mut period = Duration::from_secs(1);
24///     let mut interval = interval(period);
25///     interval.tick().await;
26///     println!("tick 1");
27///     interval.tick().await;
28///     println!("tick 2");
29///     interval.tick().await;
30///     println!("tick 3");
31/// }
32///
33/// async fn demo_interval_at() {
34///     let mut start = Instant::now() + Duration::from_millis(200);
35///     let mut period = Duration::from_secs(1);
36///     let mut interval = interval_at(start, period);
37///     interval.tick().await;
38///     println!("tick 1");
39///     interval.tick().await;
40///     println!("tick 2");
41///     interval.tick().await;
42///     println!("tick 3");
43/// }
44///
45/// async fn demo_timeout() {
46///     let duration = Duration::from_millis(500);
47///     match timeout(duration, async move {
48///         // simulate long action
49///         sleep(Duration::from_millis(500));
50///         42
51///     }).await {
52///         Ok(result) => println!("{result}"),
53///         Err(_) => println!("timeout"),
54///     }
55/// }
56///
57/// async fn demo_timeout_at() {
58///     let deadline = Instant::now() + Duration::from_millis(200);
59///     match timeout_at(deadline, async move {
60///         // simulate long action
61///         sleep(Duration::from_millis(500));
62///         42
63///     }).await {
64///         Ok(result) => println!("{result}"),
65///         Err(_) => println!("timeout"),
66///     }
67/// }
68/// ```
69pub use interval::{interval, interval_at, Interval};
70pub use sleep::{sleep, sleep_until, Sleep};
71pub use time::{Instant, SystemTime, UNIX_EPOCH};
72pub use timeout::{timeout, timeout_at, Timeout};