How to use the workerpool.pool function in workerpool

To help you get started, we’ve selected a few workerpool 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 leancloud / leanmessage-demo / server / index.js View on Github external
// http://mathjs.org/examples/advanced/web_server/index.html

var express = require('express');
var workerpool = require('workerpool');
var bodyParser = require('body-parser');
var AV = require('leanengine');
var TextMessage = require('leancloud-realtime').TextMessage;

var app = express();
app.use(bodyParser.json());
var pool = workerpool.pool(__dirname + '/math_worker.js');

var TIMEOUT = 10000; // milliseconds

var APP_ID = process.env.LC_APP_ID; // your app id
var APP_KEY = process.env.LC_APP_KEY; // your app key
var MASTER_KEY = process.env.LC_APP_MASTER_KEY; // your app master key

AV.init({
  'appId': APP_ID,
  'appKey': APP_KEY,
  'masterKey': MASTER_KEY
});

var MATH_CONV_ID = process.env.MATH_CONV_ID;
app.post('/webhook', function (req, res) {
  var messages = req.body;
github DefinitelyTyped / DefinitelyTyped / types / workerpool / workerpool-tests.ts View on Github external
import * as wp from 'workerpool';

wp.pool('foo');
wp.pool({minWorkers: 1});
wp.pool({minWorkers: 'max'});
wp.pool({minWorkers: 'max', maxWorkers: 1});
wp.pool({minWorkers: 1, maxWorkers: 1});
wp.pool({maxWorkers: 1});
wp.pool({nodeWorker: 'process'});
wp.pool({nodeWorker: 'thread'});
wp.pool({nodeWorker: 'auto'});
wp.pool({workerType: 'process'});
wp.pool({workerType: 'thread'});
wp.pool({workerType: 'web'});
wp.pool({workerType: 'auto'});
wp.pool({forkArgs: ['foo', 'bar']});
wp.pool({forkOpts: {cwd: '/tmp'}});
const pool = wp.pool();
pool.clear()
github FormidableLabs / inspectpack / lib / daemon / index.js View on Github external
constructor(opts) {
    opts = opts || {};
    this._cache = opts.cache ||
      (opts.cacheFilename ? Cache.create({ filename: opts.cacheFilename }) : null);
    if (!this._cache) {
      throw new Error("Cache is required");
    }

    this._pool = workerpool.pool(path.resolve(__dirname, "worker.js"), {
      minWorkers: cpus().length,
      maxWorkers: cpus().length,
      forkArgs: this._cache ? [JSON.stringify({ cache: this._cache.serialize() })] : []
    });
  }
github tswaters / react-thread-poc / app / types / workerpool.js View on Github external
exports.factory = async entry => {

  pool = workerpool.pool(entry);

  return async state => {
    return pool.exec('render', [state])
  }
}
github CodeChain-io / codechain-indexer / src / models / logic / utils / workerpool.ts View on Github external
const pubKey = tx.getSignerPublic().value;
                const regularKeyOwner = await getRegularKeyOwnerByPublicKey(
                    pubKey,
                    { transaction: options.transaction }
                );
                if (regularKeyOwner != null) {
                    return regularKeyOwner;
                }
                return PlatformAddress.fromPublic(pubKey, {
                    networkId: tx.unsigned.networkId()
                }).toString();
            })
        );
    }

    const pool = workerpool.pool({
        nodeWorker: "auto"
    } as any);
    const networkId = txs[0].unsigned.networkId();
    const signatureAndMessages = txs.map(tx => ({
        signature: tx.signature(),
        message: tx.unsigned.unsignedHash().toString()
    }));
    const signerPubKeys: string[][] = (await workerpool.Promise.all(
        _.chunk(signatureAndMessages, 100).map(chunk => {
            return pool.exec(getSignerPublicsFromSignatures, [chunk]);
        })
    )) as any;
    const regularKeyOwnerAndPubKeys: [
        string | null,
        string
    ][][] = await Promise.all(
github babel / broccoli-babel-transpiler / lib / parallel-api.js View on Github external
function getWorkerPool() {
  let pool;
  let globalPoolID = 'v2/broccoli-babel-transpiler/workerpool/babel-core-' + babelCoreVersion;
  let existingPool = process[globalPoolID];

  if (existingPool) {
    pool = existingPool;
  } else {
    pool = workerpool.pool(path.join(__dirname, 'worker.js'), { nodeWorker: 'auto', maxWorkers: JOBS });
    process[globalPoolID] = pool;
  }
  return pool;
}
github teppeis / duck / src / dependency-parser-wrapper.ts View on Github external
constructor(numOfWorkers = 1) {
    if (numOfWorkers < 1) {
      throw new TypeError(`numOfWorkers must be an integer >= 1, but "${numOfWorkers}"`);
    }
    this.pool = workerpool.pool(script, {
      minWorkers: "max",
      maxWorkers: numOfWorkers,
    });
  }
  async parse(filepath: string): Promise {
github linkedinlabs / icon-magic / packages / @icon-magic / generate / src / index.ts View on Github external
import { IconConfigHash, IconSet } from '@icon-magic/icon-models';
import { Logger, logger } from '@icon-magic/logger';
import { timer } from '@icon-magic/timing';
import * as path from 'path';
import * as workerpool from 'workerpool';

const LOGGER: Logger = logger('icon-magic:generate:index');
const TIMER = timer();
const pool = workerpool.pool(path.resolve(__dirname, './generate-worker.js'));

/**
 * Generate transorms the set of .svg flavors to their types by running a set of
 * plugins based on the type in which we want the output. For example, we can
 * have a different set of plugins to obtain the optimized svg and a different
 * set to get a .png "type".
 *
 * generate-worker.js is used to paralellize the generation of icons using a
 * workerpool
 *
 * @param iconSet mapping of the iconPath to the Icon class
 */
export async function generate(
  iconSet: IconSet,
  hashing = true
): Promise {
github James-Yu / LaTeX-Workshop / src / providers / preview / graphicsscaler.ts View on Github external
constructor(extension: Extension) {
        this.extension = extension
        this.pool = workerpool.pool(
            path.join(__dirname, 'graphicsscaler_worker.js'),
            { maxWorkers: 1, workerType: 'process' }
        )
    }

workerpool

Offload tasks to a pool of workers on node.js and in the browser

Apache-2.0
Latest version published 25 days ago

Package Health Score

89 / 100
Full package analysis