diff --git a/crates/guest-rust/src/rt/async_support.rs b/crates/guest-rust/src/rt/async_support.rs index 5326f419b..a33157a40 100644 --- a/crates/guest-rust/src/rt/async_support.rs +++ b/crates/guest-rust/src/rt/async_support.rs @@ -666,9 +666,12 @@ pub fn block_on(future: impl Future) -> T { drop(state); break result.unwrap(); } + // When yielding there's not much else to do here other than just go + // back and poll again -- the `callback` function will already poll + // the waitable set if applicable so just turn the loop and deliver + // an `EVENT_NONE` event. CallbackCode::Yield => { - let set = state.shared.waitable_set.try_lock().unwrap(); - event = set.as_ref().unwrap().poll() + event = (EVENT_NONE, 0, 0); } CallbackCode::Wait(_) => { let set = state.shared.waitable_set.try_lock().unwrap(); diff --git a/tests/runtime/rust/async-immediate-yield/runner.rs b/tests/runtime/rust/async-immediate-yield/runner.rs new file mode 100644 index 000000000..bd5da42e8 --- /dev/null +++ b/tests/runtime/rust/async-immediate-yield/runner.rs @@ -0,0 +1,16 @@ +include!(env!("BINDINGS")); + +struct Component; + +export!(Component); + +impl Guest for Component { + async fn run() { + foo::hi().await; + + wit_bindgen::block_on(async { + wit_bindgen::yield_async().await; + }); + println!("done"); + } +} diff --git a/tests/runtime/rust/async-immediate-yield/test.rs b/tests/runtime/rust/async-immediate-yield/test.rs new file mode 100644 index 000000000..45941c988 --- /dev/null +++ b/tests/runtime/rust/async-immediate-yield/test.rs @@ -0,0 +1,11 @@ +include!(env!("BINDINGS")); + +struct Test; + +export!(Test); + +impl exports::foo::Guest for Test { + async fn hi() { + wit_bindgen::yield_async().await; + } +} diff --git a/tests/runtime/rust/async-immediate-yield/test.wit b/tests/runtime/rust/async-immediate-yield/test.wit new file mode 100644 index 000000000..e538f3c8e --- /dev/null +++ b/tests/runtime/rust/async-immediate-yield/test.wit @@ -0,0 +1,15 @@ +package my:test; + +world runner { + import foo: interface { + hi: async func(); + } + + export run: async func(); +} + +world test { + export foo: interface { + hi: async func(); + } +}