zigar.thread.WorkQueue(ns).waitAsync(self, promise) - chung-leong/zigar GitHub Wiki
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, .{});
}
};
import { startup } from './work-queue-example-5.zig';
await startup(4);
[Error: File not found] { number: 51 }
Arguments:
self:@This()promise:Promise(void)orPromise(ThreadStartError!void)
Return value:
void