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#

silk
pub fn takeOption<T>(target: &mut Option<T>) -> Option<T>

Moves the value out of an &mut Option<T>, leaving Option.none().

DeferredHeaderRunner#

silk
pub interface DeferredHeaderRunner

Erased runner interface for deferred tasks returning a ResultHeader.

Operation runHeader#

silk
effect fn runHeader(self: &mut Self) -> ResultHeader ? &mut Scheduler | &mut MonotonicClock

Executes the async computation and encodes its outcome into a ResultHeader.

StreamEncoder#

silk
pub interface StreamEncoder<A: 'static, E: 'static>

Encodes stream items and terminal errors into ResultHeader payloads.

Operation encodeItem#

silk
fn encodeItem(self: &Self, item: &A) -> ResultHeader

Encodes one yielded item.

Operation encodeError#

silk
fn encodeError(self: &Self, error: &E) -> ResultHeader

Encodes a terminal error.

driveStreamForwarder#

silk
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 MonotonicClock

Drives a pull-backpressured forwarder loop for stream (slot, gen) (called by concrete per-stream AsyncTaskRunner structs in generated glue).

AsyncRuntime#

silk
pub struct AsyncRuntime

Static operations managing the instance-local LocalDriver, deferred op slots, and streams.

Implementation AsyncRuntime#

silk
impl AsyncRuntime

Associated function finishDeferred#

silk
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#

silk
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#

silk
pub fn cancelDeferred(slot: u32, gen: u32) -> ()

Cancels a pending deferred operation (slot, gen) cooperatively via LocalDriver.cancel.

Associated function openStreamSlot#

silk
pub fn openStreamSlot(creditSender: Sender<u32>) -> Option<HandleRef>

Allocates a stream slot and returns its (slot, gen) handle and credit receiver.

Associated function launchStream#

silk
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#

silk
pub fn pullStream(slot: u32, gen: u32, maxItems: u32) -> ()

Grants pull credit (maxItems) to stream (slot, gen) and schedules a pump.

Associated function dropStream#

silk
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#

silk
pub fn pump(budget: u32) -> i32

Drives 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#

silk
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.

View the source of this page