zigar.thread.WorkQueue(ns).waitAsync(self, promise) ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
Resolve the given promise when all threads have started and called ns.onThreadStart() (if
present). Reject the promise if any error is encountered any of the threads.
Usage
const std = @import("std");
const zigar = @import("zigar");
const WorkQueue = zigar.thread.WorkQueue(worker);
var work_queue: WorkQueue = .{};
pub fn startup(num_threads: usize, promise: zigar.function.PromiseArgOf(WorkQueue.waitAsync)) !void {
try work_queue.init(.{
.n_jobs = num_threads,
.thread_start_params = .{"/tmp/no-where"},
});
work_queue.waitAsync(promise);
}
const worker = struct {
threadlocal var file: ?std.fs.File = null;
pub fn onThreadStart(path: []const u8) !void {
file = try std.fs.openFileAbsolute(path, .{});
}
};
<?php
$m = zigar_use(__DIR__ . '/work-queue-example-5.zig');
$m->startup(4);
ZigException Object
(
[error] => file not found
)
Arguments:
self:@This()promise:Promise(void)orPromise(ThreadStartError!void)
Return value:
void