MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / callback

Function callback

crates/guest-rust/src/rt/async_support.rs:510–534  ·  view source on GitHub ↗
(event0: u32, event1: u32, event2: u32)

Source from the content-addressed store, hash-verified

508/// This function assumes that `context_get()` returns a `FutureState`.
509#[doc(hidden)]
510pub unsafe fn callback(event0: u32, event1: u32, event2: u32) -> u32 {
511 // Acquire our context-local state, assert it's not-null, and then reset
512 // the state to null while we're running to help prevent any unintended
513 // usage.
514 let state = context_get().cast::<FutureState<'static>>();
515 assert!(!state.is_null());
516 unsafe {
517 context_set(ptr::null_mut());
518 }
519
520 // Use `state` to run the `callback` function in the context of our event
521 // codes we received. If the callback decides to exit then we're done with
522 // our future so deallocate it. Otherwise put our future back in
523 // context-local storage and forward the code.
524 unsafe {
525 let rc = (*state).callback(event0, event1, event2);
526 if rc == CallbackCode::Exit {
527 drop(Box::from_raw(state));
528 } else {
529 context_set(state.cast());
530 }
531 rtdebug!(" => (cb) {rc:?}");
532 rc.encode()
533 }
534}
535
536/// Run the specified future to completion, returning the result.
537///

Callers 2

start_taskFunction · 0.85

Calls 5

context_getFunction · 0.85
context_setFunction · 0.85
dropFunction · 0.85
callbackMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected