This code:
fn main() {
wit_bindgen::block_on(async {
wit_bindgen::yield_async().await;
});
println!("done");
}
currently panics with the following message:
thread 'main' (1) panicked at .../wit-bindgen-0.62.0/src/rt/async_support.rs:671:38:
called Option::unwrap() on a None value
It isn't specific to yield_async. Any wake that happens while the task set is being polled, before the first host call, hits it too. Putting a host call first avoids it, e.g. awaiting wasip3::clocks::monotonic_clock::wait_for(1_000_000). After that, the same yields work.
This is because SharedTaskState::waitable_set starts as None and is only created in add_waitable. The waitable set is unwrapped unconditionally:
CallbackCode::Yield => {
let set = state.shared.waitable_set.try_lock().unwrap();
event = set.as_ref().unwrap().poll()
}
I don't know if there is a good rational for this, but perhaps the waitable_set should not be an Option or the arm should return (EVENT_NONE, 0, 0) instead of unwrapping.
This code:
currently panics with the following message:
It isn't specific to
yield_async. Any wake that happens while the task set is being polled, before the first host call, hits it too. Putting a host call first avoids it, e.g. awaitingwasip3::clocks::monotonic_clock::wait_for(1_000_000). After that, the same yields work.This is because
SharedTaskState::waitable_setstarts asNoneand is only created inadd_waitable. The waitable set is unwrapped unconditionally:I don't know if there is a good rational for this, but perhaps the
waitable_setshould not be anOptionor the arm should return(EVENT_NONE, 0, 0)instead of unwrapping.