File: timeout.rs

package info (click to toggle)
rust-async-std 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,992 kB
  • sloc: sh: 13; makefile: 8
file content (26 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (3)
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
use std::time::Duration;

use async_std::future::timeout;
use async_std::task;

#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn timeout_future_many() {
    task::block_on(async {
        let futures = (0..10)
            .map(|i| {
                timeout(Duration::from_millis(i * 50), async move {
                    task::sleep(Duration::from_millis(i)).await;
                    Ok::<(), async_std::future::TimeoutError>(())
                })
            })
            .collect::<Vec<_>>();

        for future in futures {
            future.await.unwrap().unwrap();
        }
    });
}