zigar.thread.WorkQueue(ns).deinitAsync(self, promise) - chung-leong/zigar GitHub Wiki

Shutdown the work queue, terminating worker threads and freeing memory used. Resolve the given promise when the process is complete.

You can use promisify() to define a basic shutdown function instead.

Generally, you need to shut down the work queue manually only in Node.js. In the browser, clean-up isn't necessary (or possible even). The user will simply close the tab.

Usage

const std = @import("std");

const zigar = @import("zigar");

var work_queue: zigar.thread.WorkQueue(worker) = .{};

pub fn shutdown(promise: zigar.function.Promise(void)) !void {
    work_queue.deinitAsync(promise);
}

pub const print = work_queue.promisify(worker.print);

const worker = struct {
    pub fn onThreadStart() !void {
        std.debug.print("Thread starting\n", .{});
    }

    pub fn onThreadEnd() void {
        std.debug.print("Thread exiting\n", .{});
    }

    pub fn print() void {
        std.debug.print("Hello\n", .{});
    }
};
import { print, shutdown } from './work-queue-example-3.zig';

await print();
await shutdown();
Thread starting
Hello
Thread exiting

Arguments:

  • self: @This()
  • promise: ?Promise(void)

Return value:

void


WorkQueue(ns) | Promise(T)