Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/guest-rust/src/rt/async_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,12 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> 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();
Expand Down
16 changes: 16 additions & 0 deletions tests/runtime/rust/async-immediate-yield/runner.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
11 changes: 11 additions & 0 deletions tests/runtime/rust/async-immediate-yield/test.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
15 changes: 15 additions & 0 deletions tests/runtime/rust/async-immediate-yield/test.wit
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading