use async_runtime::{Priority, RuntimeBuilder};
use futures_lite::future;
use std::num::NonZeroUsize;
use std::sync::mpsc;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let runtime = RuntimeBuilder::new(NonZeroUsize::new(1).expect("non-zero")).build()?;
runtime
.spawn(Priority::High, async {
for _ in 0..10_000 {
future::yield_now().await;
}
})?
.detach();
let (background_tx, background_rx) = mpsc::channel();
let background = runtime.spawn(Priority::Background, async move {
background_tx.send("background made progress").unwrap();
})?;
future::block_on(background);
assert_eq!(background_rx.recv()?, "background made progress");
println!("background ran while high-priority work remained runnable");
runtime.shutdown_now()?;
Ok(())
}