use std::{thread, time::{Duration, Instant}};
use smol::{LocalExecutor, Timer, channel};
use floop::floop;
#[test]
fn return_infinite_loop() {
let start = Instant::now();
let thread = thread::spawn(|| {
let executor = LocalExecutor::new();
let (send, receive) = channel::unbounded();
executor.spawn(async move {
loop {
Timer::after(Duration::from_millis(50)).await;
send.send(()).await.unwrap();
}
}).detach();
let task = executor.spawn(async move {
let mut counter = 5;
floop! {
unbiased
return
result in receive.recv()=> {
result.unwrap();
counter -= 1;
if counter == 0 {
return;
}
}
}
});
while !task.is_finished() {
executor.try_tick();
}
});
while start.elapsed() < Duration::from_millis(1000) {
if thread.is_finished() {
thread.join().unwrap();
return;
}
}
panic!("the threat is stuck");
}