How to use the threads.Pool function in threads

To help you get started, we’ve selected a few threads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypeScriptToLua / TypeScriptToLua / test / threaded_runner.ts View on Github external
console.log("-----------------");
}

config.set({
  basepath: {
    node: __dirname,
  }
});

let cpuCount = os.cpus().length + 1;
if ("TRAVIS" in process.env && "CI" in process.env) {
    // fixed thread count for CI
    cpuCount = 8;
}
const testFiles: string[] = glob.sync("./test/**/*.spec.js");
const pool = new Pool(cpuCount);
let jobCounter = 0;
const testStartTime = new Date();
const fileCount = testFiles.length;
let exitWithError = false;
let totalTestCount = 0;
let totalFailedTestCount = 0;

console.log(
    `Running tests: ${fileArrToString(testFiles)} with ${cpuCount} threads`);

testFiles.forEach(file => {
    pool.run("./test_thread")
        .send({files: [file]})
        .on("done",
            (testCount, failedTestCount) => {
              if (failedTestCount !== 0) {
github gcba-iris / iris / bin / iris.js View on Github external
const newThreadPool = (config) => {
    logger.verbose('Creating new threadpool');

    return config.threads ? new Threads.Pool(config.threads) : new Threads.Pool();
};
github ceresimaging / fast-lzw / index.js View on Github external
constructor (numWorkers, outputBuffer) {
    this.outputBuffer= outputBuffer
    this.usingWorkers = numWorkers > 0
    if (this.usingWorkers > 0) {
      this.pool = Pool(
        () => spawn(new Worker(), numWorkers)
      )  
    } else {
      this.pool = null
    }
  }
  prepareDataForTransfer (typedArrays) {
github Leko / hothouse / packages / hothouse / src / WorkerPool.js View on Github external
constructor(options: WorkerInit) {
    const { concurrency, reporter } = options;

    this.options = options;
    this.pool = new Pool(concurrency);
    this.pool.on("error", (job, e) => reporter.reportError(e));
  }