diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-16 08:28:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-16 08:28:34 -0800 |
commit | 19f1fc36bd567377bde4a2c6818c6b606d89d488 (patch) | |
tree | 44ab1d6dceabbb8353ab6369779cce4d3333075f /tokio/tests/rt_common.rs | |
parent | 3f0eabe7798de624f5ee9c7562803bfb97e6088f (diff) |
task: return `JoinHandle` from spawn (#1777)
`tokio::spawn` now returns a `JoinHandle` to obtain the result of the task:
Closes #887.
Diffstat (limited to 'tokio/tests/rt_common.rs')
-rw-r--r-- | tokio/tests/rt_common.rs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs index 6e8e58fb..81fe6801 100644 --- a/tokio/tests/rt_common.rs +++ b/tokio/tests/rt_common.rs @@ -80,7 +80,7 @@ rt_test! { } #[test] - fn spawn_one() { + fn spawn_one_bg() { let mut rt = rt(); let out = rt.block_on(async { @@ -97,6 +97,29 @@ rt_test! { } #[test] + fn spawn_one_join() { + let mut rt = rt(); + + let out = rt.block_on(async { + let (tx, rx) = oneshot::channel(); + + let handle = tokio::spawn(async move { + tx.send("ZOMG").unwrap(); + "DONE" + }); + + let msg = assert_ok!(rx.await); + + let out = assert_ok!(handle.await); + assert_eq!(out, "DONE"); + + msg + }); + + assert_eq!(out, "ZOMG"); + } + + #[test] fn spawn_two() { let mut rt = rt(); @@ -180,7 +203,7 @@ rt_test! { tokio::spawn(poll_fn(move |_| { assert_eq!(2, Arc::strong_count(&cnt)); - Poll::Pending + Poll::<()>::Pending })); }); |