Skip to content

Commit a5253b1

Browse files
committed
remove CallbackCode::Poll
As of WebAssembly/component-model#578, that code no longer exists. Instead, we can emulate it via a combination of `CallbackCode::Yield` and `waitable-set.poll`. I'm working on a PR to make the corresponding changes to Wasmtime, and needed this to make the tests pass.
1 parent c86323d commit a5253b1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

crates/guest-rust/src/rt/async_support.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ impl FutureState<'_> {
214214
// processing the future here anyway.
215215
me.cancel_inter_task_stream_read();
216216

217-
let mut context = Context::from_waker(&me.waker_clone);
218-
219217
loop {
218+
let mut context = Context::from_waker(&me.waker_clone);
219+
220220
// On each turn of this loop reset the state to "polling"
221221
// which clears out any pending wakeup if one was sent. This
222222
// in theory helps minimize wakeups from previous iterations
@@ -255,8 +255,12 @@ impl FutureState<'_> {
255255
assert!(!me.tasks.is_empty());
256256
if me.waker.sleep_state.load(Ordering::Relaxed) == SLEEP_STATE_WOKEN {
257257
if me.remaining_work() {
258-
let waitable = me.waitable_set.as_ref().unwrap().as_raw();
259-
break CallbackCode::Poll(waitable);
258+
let (event0, event1, event2) =
259+
me.waitable_set.as_ref().unwrap().poll();
260+
if event0 != EVENT_NONE {
261+
me.deliver_waitable_event(event1, event2);
262+
continue;
263+
}
260264
}
261265
break CallbackCode::Yield;
262266
}
@@ -415,7 +419,6 @@ enum CallbackCode {
415419
Exit,
416420
Yield,
417421
Wait(u32),
418-
Poll(u32),
419422
}
420423

421424
impl CallbackCode {
@@ -424,7 +427,6 @@ impl CallbackCode {
424427
CallbackCode::Exit => 0,
425428
CallbackCode::Yield => 1,
426429
CallbackCode::Wait(waitable) => 2 | (waitable << 4),
427-
CallbackCode::Poll(waitable) => 3 | (waitable << 4),
428430
}
429431
}
430432
}
@@ -546,9 +548,7 @@ pub fn block_on<T: 'static>(future: impl Future<Output = T>) -> T {
546548
drop(state);
547549
break result.unwrap();
548550
}
549-
CallbackCode::Yield | CallbackCode::Poll(_) => {
550-
event = state.waitable_set.as_ref().unwrap().poll()
551-
}
551+
CallbackCode::Yield => event = state.waitable_set.as_ref().unwrap().poll(),
552552
CallbackCode::Wait(_) => event = state.waitable_set.as_ref().unwrap().wait(),
553553
}
554554
}

0 commit comments

Comments
 (0)