File tree Expand file tree Collapse file tree 1 file changed +0
-52
lines changed Expand file tree Collapse file tree 1 file changed +0
-52
lines changed Original file line number Diff line number Diff line change 7
7
A library for working with timers, timeouts, and intervals with the ` futures `
8
8
crate.
9
9
10
- ``` toml
11
- # Cargo.toml
12
- [dependencies ]
13
- futures-timer = " 0.3"
14
- ```
15
-
16
- An example of using a ` Delay ` is:
17
-
18
- ``` rust
19
- use std :: time :: Duration ;
20
-
21
- use futures :: prelude :: * ;
22
- use futures_timer :: Delay ;
23
-
24
- async fn main () -> Result <(), Box <dyn Error + Send + Sync + 'static >> {
25
- Delay :: new (Duration :: from_secs (3 ))
26
- . map (| ()| println! (" printed after three seconds" ))
27
- . await ? ;
28
- }
29
- ```
30
-
31
- And using an ` Interval ` :
32
-
33
- ``` rust
34
- use std :: time :: Duration ;
35
-
36
- use futures :: prelude :: * ;
37
- use futures_timer :: Interval ;
38
-
39
- #[runtime:: main]
40
- async fn main () -> Result <(), Box <dyn Error + Send + Sync + 'static >> {
41
- Interval :: new (Duration :: from_secs (4 ))
42
- . take (4 )
43
- . for_each (| ()| Ok (println! (" printed after three seconds" )))
44
- . await ? ;
45
- }
46
- ```
47
-
48
- Or timing out a future
49
-
50
- ``` rust
51
- use std :: time :: Duration ;
52
-
53
- use futures_timer :: FutureExt ;
54
-
55
- async fn main () -> Result <(), Box <dyn Error + Send + Sync + 'static >> {
56
- // create a future that will take at most 3 seconds to resolve
57
- let future = long_running_future ()
58
- . timeout (Duration :: from_secs (3 ));
59
- }
60
- ```
61
-
62
10
# License
63
11
64
12
This project is licensed under either of
You can’t perform that action at this time.
0 commit comments