Skip to content

Latest commit

 

History

History
93 lines (62 loc) · 2.06 KB

tpl.readme.md

File metadata and controls

93 lines (62 loc) · 2.06 KB

About

{{pkg.description}}

The package provides a WASM bridge API and abstraction for scheduling function calls via:

  • once: setTimeout() / clearTimeout()
  • interval: setInterval() / clearInterval()
  • immediate: setImmediate() / clearImmediate()(1)
  • raf: requestAnimationFrame() / cancelAnimationFrame()(1)

(1) Fallback provided in case the JS host env has no native support

These different types of delayed execution are unified into the single schedule() function and the ScheduleType enum. Scheduled callbacks can be cancelled via cancel()...

Zig example:

const wasm = @import("wasm-api");
const schedule = @import("wasm-api-schedule");

// ...

// the WASM API modules auto-initialize themselves if the root source
// file exposes a `WASM_ALLOCATOR`, otherwise you'll have to initialize manually:
try schedule.init(customAllocator);

// user callback function
fn exampleCallback(raw: ?*anyopaque) callconv(.C) void {
    if (wasm.ptrCast(*u32, raw)) |state| {
        // do something ...
    }
}

// arbitrary user state
var state: u32 = 0xdecafbad;

// schedule a single/one-off callback 500ms in the future
const listenerID = try schedule.schedule(
    .once,
    500,
    exampleCallback,
    &state,
);

// ...or maybe cancel it again
schedule.cancel(listenerID);

IMPORTANT: In Zig v0.12+ all event handlers must explicitly specify callconv(.C) See docs for more reference.

Also see the zig-counter and zig-todo-list example projects for more advanced usage...

{{meta.status}}

{{repo.supportPackages}}

{{repo.relatedPackages}}

{{meta.blogPosts}}

Installation

{{pkg.install}}

{{pkg.size}}

Dependencies

{{pkg.deps}}

{{repo.examples}}

API

{{pkg.docs}}

TODO