silk.wasm.async_bridge.
Caller-driven asynchronous runtime for WasmDeferred<A, E> and WasmStream<A, E> on
wasm32-unknown-unknown, backed by silk.concurrency.local_scheduler.LocalDriver.
Details#
Imported only by generated glue modules that export at least one async WasmDeferred,
? &mut Scheduler, or WasmStream function/method, so synchronous-only modules never import
silk_bridge#* host functions.
Import as AsyncRuntime with import silk.wasm.async_bridge { AsyncRuntime }.
Public declarations: 5.
takeOption#
pub fn takeOption<T>(target: &mut Option<T>) -> Option<T>Moves the value out of an &mut Option<T>, leaving Option.none().
DeferredHeaderRunner#
pub interface DeferredHeaderRunnerErased runner interface for deferred tasks returning a ResultHeader.
Operation runHeader#
effect fn runHeader(self: &mut Self) -> ResultHeader ? &mut Scheduler | &mut MonotonicClockExecutes the async computation and encodes its outcome into a ResultHeader.
StreamEncoder#
pub interface StreamEncoder<A: 'static, E: 'static>Encodes stream items and terminal errors into ResultHeader payloads.
Operation encodeItem#
fn encodeItem(self: &Self, item: &A) -> ResultHeaderEncodes one yielded item.
Operation encodeError#
fn encodeError(self: &Self, error: &E) -> ResultHeaderEncodes a terminal error.
driveStreamForwarder#
pub effect fn driveStreamForwarder<A: 'static, E: 'static, C: StreamEncoder<A, E> + 'static>(
slot: u32,
gen: u32,
creditReceiver: Receiver<u32>,
dataReceiver: Receiver<StreamItem<A, E>>,
encoder: C,
) -> ()
? &mut Scheduler | &mut MonotonicClockDrives a pull-backpressured forwarder loop for stream (slot, gen) (called by concrete
per-stream AsyncTaskRunner structs in generated glue).
AsyncRuntime#
pub struct AsyncRuntimeStatic operations managing the instance-local LocalDriver, deferred op slots, and streams.
Implementation AsyncRuntime#
impl AsyncRuntimeAssociated function finishDeferred#
pub fn finishDeferred(slot: u32, gen: u32, header: ResultHeader) -> ()Records the completion of deferred op (slot, gen) and either saves it for immediate
synchronous return or delivers it to JS via silk_bridge#deferred_settle.
Associated function startDeferred#
pub fn startDeferred<T: DeferredHeaderRunner + 'static>(
task: T,
outPtr: *mut ResultHeader,
) -> ()Spawns a concrete DeferredHeaderRunner onto LocalDriver, attempts one non-blocking
step(1) when not busy, and writes either its immediate result or TAG_PENDING(slot, gen)
into outPtr.
Associated function cancelDeferred#
pub fn cancelDeferred(slot: u32, gen: u32) -> ()Cancels a pending deferred operation (slot, gen) cooperatively via LocalDriver.cancel.
Associated function openStreamSlot#
pub fn openStreamSlot(creditSender: Sender<u32>) -> Option<HandleRef>Allocates a stream slot and returns its (slot, gen) handle and credit receiver.
Associated function launchStream#
pub fn launchStream<F: AsyncTaskRunner + 'static>(
slot: u32,
gen: u32,
forwarder: F,
producer: Option<AnyBox<any AsyncTaskRunner>>,
outPtr: *mut ResultHeader,
) -> ()Spawns the concrete forwarder task (and optional producer task) for an open stream slot
(slot, gen) and writes its handle into outPtr.
Associated function pullStream#
pub fn pullStream(slot: u32, gen: u32, maxItems: u32) -> ()Grants pull credit (maxItems) to stream (slot, gen) and schedules a pump.
Associated function dropStream#
pub fn dropStream(slot: u32, gen: u32) -> ()Drops stream (slot, gen), cancelling its forwarder and producer fibers and closing its
underlying channel receiver.
Associated function pump#
pub fn pump(budget: u32) -> i32Drives up to budget ready task activations on LocalDriver and arms the next pump
callback via silk_bridge#schedule_pump. Returns 0 if re-entered while busy, else 1.
Associated function shutdown#
pub fn shutdown() -> ()Cancels all live async tasks/streams and destroys the instance's LocalDriver.
Must only be called from silk_wb_shutdown() at depth 0.
Category: WebAssembly.
Profiles: wasm32-unknown-unknown, wasm64-unknown-unknown.