Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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;
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()
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() })] : []
});
}
exports.factory = async entry => {
pool = workerpool.pool(entry);
return async state => {
return pool.exec('render', [state])
}
}
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(
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;
}
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 {
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 {
constructor(extension: Extension) {
this.extension = extension
this.pool = workerpool.pool(
path.join(__dirname, 'graphicsscaler_worker.js'),
{ maxWorkers: 1, workerType: 'process' }
)
}