runtime: add block_on_all (#398)

Signed-off-by: Marc-Antoine Perennou <[email protected]>
This commit is contained in:
Marc-Antoine Perennou
2018-06-14 22:13:39 -07:00
committed by Carl Lerche
parent 011ebf44eb
commit 71c8f561e3
2 changed files with 55 additions and 0 deletions
+30
View File
@@ -173,3 +173,33 @@ fn spawn_many() {
runtime.shutdown_on_idle().wait().unwrap();
assert_eq!(ITER, *cnt.lock().unwrap());
}
#[test]
fn spawn_from_block_on_all() {
let cnt = Arc::new(Mutex::new(0));
let c = cnt.clone();
let mut runtime = Runtime::new().unwrap();
let msg = runtime
.block_on_all(lazy(move || {
{
let mut x = c.lock().unwrap();
*x = 1 + *x;
}
// Spawn!
tokio::spawn(lazy(move || {
{
let mut x = c.lock().unwrap();
*x = 1 + *x;
}
Ok::<(), ()>(())
}));
Ok::<_, ()>("hello")
}))
.unwrap();
assert_eq!(2, *cnt.lock().unwrap());
assert_eq!(msg, "hello");
}