forked from yewstack/yew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.rs
30 lines (25 loc) · 769 Bytes
/
time.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Utilities for bridging time and tasks.
use std::future::Future;
use std::time::Duration;
use futures::stream::Stream;
use crate::platform::imp::time as imp;
/// Waits until duration has elapsed.
///
/// # Panics
///
/// On some platforms, if the prodvided duration cannot be converted to u32 in milliseconds, this
/// function will panic.
#[inline(always)]
pub fn sleep(dur: Duration) -> impl Future<Output = ()> {
imp::sleep(dur)
}
/// Creates a Stream that yields an item after every period has elapsed.
///
/// # Panics
///
/// On some platforms, if the prodvided period cannot be converted to u32 in milliseconds, this
/// function will panic.
#[inline(always)]
pub fn interval(period: Duration) -> impl Stream<Item = ()> {
imp::interval(period)
}