zigar.thread.WorkQueue(ns).wait(self) ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
Wait until all threads have started and called ns.onThreadStart() (if present). Return any error
encountered by any of the threads.
A deadlock will occur if this function is called in the main thread and ns.onThreadStart() calls
a PHP function or performs an IO operation.
When this function returns an error, a shutdown of the queue will have already occurred.
Usage
const std = @import("std");
const zigar = @import("zigar");
var work_queue: zigar.thread.WorkQueue(ns) = .{};
pub fn startup(num_threads: usize) !void {
try work_queue.init(.{
.n_jobs = num_threads,
.thread_start_params = .{true},
});
try work_queue.wait();
}
const ns = struct {
pub fn onThreadStart(do_the_impossible: bool) !void {
if (do_the_impossible) return error.Failure;
}
};
<?php
$m = zigar_use(__DIR__ . '/work-queue-example-4.zig');
try {
$m->startup(4);
} catch (Exception $e) {
echo "$e\n";
}
ZigException: failure in /home/rwiggum/examples/work-queue-example-4.php:6
Stack trace:
#0 /home/rwiggum/examples/work-queue-example-4.php(6): work-queue-example-4->startup(4)
#1 {main}
Arguments:
self:@This()
Return value:
void or ThreadStartError!void