add new spawn sig tests

This commit is contained in:
Rob Ede 2021-09-01 20:38:01 +01:00
parent b2330ce68a
commit 9df1b45fd1
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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: Future<Output = Result<(), JoinError>>>(_f: F) {}
g(actix_rt::spawn(async {}));
// g(actix_rt::spawn(async { 1 })); // compile err
fn h<F: Future<Output = Result<R, JoinError>>, R>(_f: F) {}
h(actix_rt::spawn(async {}));
h(actix_rt::spawn(async { 1 }));
}