mod common;
use
{
async_executors :: { AsyncStd } ,
async_nursery :: { Nursery, NurseExt } ,
common :: { DynResult, setup_tracing } ,
futures :: { channel::mpsc, StreamExt } ,
futures_timer :: { Delay } ,
std :: { time::Duration } ,
tracing_crate :: { info } ,
};
async fn resource_drop( senders: Vec<mpsc::UnboundedSender<()>> ) -> DynResult<()>
{
let (nursery, _output) = Nursery::new( AsyncStd );
info!( "nursery created" );
for tx in senders.into_iter()
{
nursery.nurse( slow( tx ) )?;
}
Delay::new( Duration::from_millis(10) ).await;
info!( "drop Nursery and NurseryStream" );
Ok(())
}
async fn slow( tx: mpsc::UnboundedSender<()> ) -> DynResult<()>
{
info!( "spawned slow" );
Delay::new( Duration::from_secs(60) ).await;
tx.unbounded_send(())?;
Ok(())
}
#[ async_std::main ]
async fn main() -> DynResult<()>
{
setup_tracing();
let (tx , mut rx ) = mpsc::unbounded();
let (tx2, mut rx2) = mpsc::unbounded();
resource_drop( vec![tx, tx2] ).await?;
assert_eq!( rx .next().await, None );
assert_eq!( rx2.next().await, None );
Ok(())
}