#![ cfg( feature = "implementation" ) ]
#![ cfg(not( target_arch = "wasm32" )) ]
mod common;
use common::{ import::*, DynSendResult };
#[ async_std::test ]
async fn mixed_spawn_consume() -> DynSendResult<()>
{
let (nursery, mut output) = Nursery::new( AsyncStd );
let mut accu = 0;
nursery.nurse( async { 5 + 5 } )?;
accu += output.next().await.unwrap();
nursery.nurse( async { 5 + 5 } )?;
accu += output.next().await.unwrap();
assert_eq!( 20, accu );
drop(nursery);
assert_eq!( None, output.next().await );
Ok(())
}
#[ async_std::test ]
async fn mixed_spawn_consume_concurrent() -> DynSendResult<()>
{
async fn spawner( nursery: Nursery<AsyncStd, usize> ) -> DynSendResult<()>
{
nursery.nurse( async { 5 + 5 } )?;
Ok(())
}
let (nursery, output) = Nursery::new( AsyncStd );
let handle = AsyncStd.spawn_handle( spawner( nursery.clone() ) )?;
let handle2 = AsyncStd.spawn_handle( spawner( nursery.clone() ) )?;
nursery.nurse( async { 5 + 5 } )?;
assert!( handle .await.is_ok() );
assert!( handle2.await.is_ok() );
drop(nursery);
let sum = output.fold( 0, |acc, x| async move { acc + x } ).await;
assert_eq!( 30, sum );
Ok(())
}