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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT/Apache-2.0 License, at your convenience
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2020 Datadog, Inc.
//
//! glommio::timer is a module that provides timing related primitives.
use ;
pub use ;
type Result<T> = crateResult;
/// Sleep for some time.
///
/// ```
/// use glommio::{timer::sleep, LocalExecutor};
/// use std::time::Duration;
///
/// let ex = LocalExecutor::default();
///
/// ex.run(async {
/// sleep(Duration::from_millis(100)).await;
/// });
/// ```
pub async
/// Executes a future with a specified timeout
///
/// Returns a `Result`, with `Ok` if the future ran to completion
/// or a [`GlommioError::TimedOut`] error if the timeout was reached
///
/// ```
/// # use glommio::{
/// # timer::{timeout, Timer},
/// # LocalExecutor,
/// # };
/// # use std::time::Duration;
/// # let ex = LocalExecutor::default();
/// # ex.run(async {
/// timeout(Duration::from_millis(1), async move {
/// // this future will wait for 100ms, but won't complete, as the timeout is 1ms
/// Timer::new(Duration::from_millis(100)).await;
/// Ok(())
/// })
/// .await;
/// # });
/// ```
///
/// [`GlommioError::TimedOut`]: crate::GlommioError::TimedOut
pub async