mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
task: return JoinHandle from spawn (#1777)
`tokio::spawn` now returns a `JoinHandle` to obtain the result of the task: Closes #887.
This commit is contained in:
@@ -80,7 +80,7 @@ rt_test! {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawn_one() {
|
||||
fn spawn_one_bg() {
|
||||
let mut rt = rt();
|
||||
|
||||
let out = rt.block_on(async {
|
||||
@@ -96,6 +96,29 @@ rt_test! {
|
||||
assert_eq!(out, "ZOMG");
|
||||
}
|
||||
|
||||
#[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
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user