2020-04-25 15:36:20 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
use async_std::future::timeout;
|
|
|
|
use async_std::task;
|
|
|
|
|
2020-04-26 16:00:00 +00:00
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
|
2020-04-25 15:36:20 +00:00
|
|
|
#[test]
|
2020-04-26 16:00:00 +00:00
|
|
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
2020-04-25 15:36:20 +00:00
|
|
|
fn timeout_future_many() {
|
|
|
|
task::block_on(async {
|
|
|
|
let futures = (0..100)
|
|
|
|
.map(|i| {
|
|
|
|
timeout(Duration::from_millis(i * 10), async move {
|
|
|
|
task::sleep(Duration::from_millis(i)).await;
|
|
|
|
Ok::<(), async_std::future::TimeoutError>(())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
for future in futures {
|
|
|
|
future.await.unwrap().unwrap();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|