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 JavaScript function or try 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;
    }
};
import { startup } from './work-queue-example-4.zig';

try {
    await startup(4);
} catch (err) {
    console.log(err);
}
Error: Failure
    at startup (<anonymous>:1355:26)
    at file:///home/rwiggum/examples/work-queue-example-4.js:4:11
    at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
  number: 170
}

Arguments:

  • self: @This()

Return value:

void or ThreadStartError!void


WorkQueue(ns) | ThreadStartError

⚠️ **GitHub.com Fallback** ⚠️