zigar.thread.WorkQueue(ns).deinitAsync(self, promise) ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
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.
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", .{});
}
};
<?php
$m = zigar_use(__DIR__ . '/work-queue-example-3.zig');
$m->print();
$m->shutdown();
Thread starting
Hello
Thread exiting
Arguments:
self:@This()promise:?Promise(void)
Return value:
void