zigar.thread.end() - chung-leong/zigar GitHub Wiki

Discontinue the handling of call requests from other threads, allowing for normal shutdown of Node.js event loop.

This function does nothing when the target platform is WebAssembly.

Usage

const std = @import("std");
const zigar = @import("zigar");

pub fn startup() !void {
    try zigar.thread.use();
}

pub fn spawn(cb: *const fn () void) !void {
    const thread = try std.Thread.spawn(.{}, run, .{cb});
    thread.detach();
}

fn run(cb: *const fn () void) void {
    cb();
}

pub fn shutdown() void {
    zigar.thread.end();
}
import { spawn, startup, shutdown } from './thread-example-1.zig';

startup();
spawn(() => {
    console.log('Hello world');
});
await new Promise(r => setTimeout(r, 200));
shutdown();
Hello world

Return value:

void