From 9df1b45fd14577bb2b185fd556433bab9fe66630 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 1 Sep 2021 20:38:01 +0100 Subject: [PATCH] add new spawn sig tests --- actix-rt/CHANGES.md | 3 +++ actix-rt/tests/tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 483999ce..42879e12 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* The `spawn` method can now resolve with non-unit outputs. [#369] + +[#369]: https://github.com/actix/actix-net/pull/369 ## 2.2.0 - 2021-03-29 diff --git a/actix-rt/tests/tests.rs b/actix-rt/tests/tests.rs index 86fba96d..ff91769c 100644 --- a/actix-rt/tests/tests.rs +++ b/actix-rt/tests/tests.rs @@ -9,6 +9,7 @@ use std::{ }; use actix_rt::{Arbiter, System}; +use futures_core::Future; use tokio::sync::oneshot; #[test] @@ -298,3 +299,26 @@ fn try_current_no_system() { fn try_current_with_system() { System::new().block_on(async { assert!(System::try_current().is_some()) }); } + +#[actix_rt::test] +async fn spawn_local() { + // demonstrate that spawn -> R is strictly more capable than spawn -> () + + assert_eq!(actix_rt::spawn(async { (|| {})() }).await.unwrap(), ()); + assert_eq!(actix_rt::spawn(async { 1 }).await.unwrap(), 1); + assert!(actix_rt::spawn(async { panic!("") }).await.is_err()); + + actix_rt::spawn(async { tokio::time::sleep(Duration::from_millis(50)).await }) + .await + .unwrap(); + + use actix_rt::task::JoinError; + + fn g>>(_f: F) {} + g(actix_rt::spawn(async {})); + // g(actix_rt::spawn(async { 1 })); // compile err + + fn h>, R>(_f: F) {} + h(actix_rt::spawn(async {})); + h(actix_rt::spawn(async { 1 })); +}