diff options
author | Marc-Antoine Perennou <Marc-Antoine@Perennou.com> | 2018-06-15 05:13:39 +0000 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2018-06-14 22:13:39 -0700 |
commit | 71c8f561e36035bba4938cc5b199a93beb3d71e4 (patch) | |
tree | fa6cd0ec9ca891967ba3aa702e3a4eb5bd0744bd /tests | |
parent | 011ebf44eb1f7924259b830f0c4257019f21ad5f (diff) |
runtime: add block_on_all (#398)
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/runtime.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/runtime.rs b/tests/runtime.rs index 7012a178..738e4a9d 100644 --- a/tests/runtime.rs +++ b/tests/runtime.rs @@ -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"); +} |