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

Function start_task

crates/guest-rust/src/rt/async_support.rs:485–501  ·  view source on GitHub ↗
(task: impl Future<Output = ()> + 'static)

Source from the content-addressed store, hash-verified

483/// immediately with its result.
484#[doc(hidden)]
485pub fn start_task(task: impl Future<Output = ()> + 'static) -> i32 {
486 // Allocate a new `FutureState` which will track all state necessary for
487 // our exported task.
488 let state = Box::into_raw(Box::new(FutureState::new(Box::pin(task))));
489
490 // Store our `FutureState` into our context-local-storage slot and then
491 // pretend we got EVENT_NONE to kick off everything.
492 //
493 // SAFETY: we should own `context.set` as we're the root level exported
494 // task, and then `callback` is only invoked when context-local storage is
495 // valid.
496 unsafe {
497 assert!(context_get().is_null());
498 context_set(state.cast());
499 callback(EVENT_NONE, 0, 0) as i32
500 }
501}
502
503/// Handle a progress notification from the host regarding either a call to an
504/// async-lowered import or a stream/future read/write operation.

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
context_setFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected