{{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}}
{{pkg.install}}
{{pkg.size}}
{{pkg.deps}}
{{repo.examples}}
{{pkg.docs}}
TODO