1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 23:17:43 +02:00

spawn should allow futures with non-unit outputs (#369)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Ibraheem Ahmed
2021-09-01 16:51:03 -04:00
committed by GitHub
parent 4644fa41cf
commit 2b1edb95ea
3 changed files with 63 additions and 5 deletions

View File

@ -1,4 +1,5 @@
use std::{
future::Future,
sync::{
atomic::{AtomicBool, Ordering},
mpsc::channel,
@ -8,7 +9,7 @@ use std::{
time::{Duration, Instant},
};
use actix_rt::{Arbiter, System};
use actix_rt::{task::JoinError, Arbiter, System};
use tokio::sync::oneshot;
#[test]
@ -298,3 +299,27 @@ fn try_current_no_system() {
fn try_current_with_system() {
System::new().block_on(async { assert!(System::try_current().is_some()) });
}
#[allow(clippy::unit_cmp)]
#[test]
fn spawn_local() {
System::new().block_on(async {
// 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();
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 }));
})
}