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;
signerPubKey.map(
async (
signerPubKey: string
): Promise<[string | null, string]> => {
const regularKeyOwner = await getRegularKeyOwnerByPublicKey(
signerPubKey,
options
);
return [regularKeyOwner, signerPubKey];
}
)
);
})
);
const chunks: string[][] = (await workerpool.Promise.all(
regularKeyOwnerAndPubKeys.map(
(
chunk: [string | null, string][]
): workerpool.Promise => {
return pool.exec(getSignersFromPubKeyAndRegularKeyOwner, [
chunk.map(([regularKeyOwner, signerPubKey]) => {
return {
regularKeyOwner,
signerPubKey
};
}),
networkId
]);
}
)
)) as any; // The bug of workerpool type definition
return {
closureSymbols: dep.closureSymbols,
path: dep.path,
type: dep.type,
language: dep.language,
// Don't copy `import.from` to avoid circular dependency in JSON.stringify.
imports: dep.imports.map(i => ({
symOrPath: i.symOrPath,
// Convert getter methods to properties to transfer with postMessage() to workers.
isGoogRequire: i.isGoogRequire(),
isEs6Import: i.isEs6Import(),
})),
};
}
workerpool.worker({ parseDependency: parse });
const cacheCls = cacheOpts.cls || Cache.NoopCache.name;
delete cacheOpts.cls;
const cache = Cache[cacheCls].create(cacheOpts);
// Create worker methods for each corresponding action.
// The generated methods look like `sizes(...).then(...)`
const wrapMethod = (action, compressor) => (args) =>
new Promise((resolve, reject) =>
actions(action)(
Object.assign({}, args, { compressor }),
(err, result) => err ? reject(err) : resolve(result)
));
// Create each action method, injecting a compressor
// instance for each one.
workerpool.worker(
Object.keys(actions.ACTIONS).reduce(
(acc, action) => Object.assign({}, acc, {
[action]: wrapMethod(
action,
Compressor.create({ cache })
)
}),
{}
)
);
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()
const workers = {add, hello};
type IWorkers = typeof workers;
pool.proxy().then((proxy) => {
proxy.add(1, 2);
proxy.hello();
});
pool.proxy().then((proxy) => {
proxy.add(1, 2);
proxy.hello();
});
new wp.Promise.CancellationError();
new wp.Promise.TimeoutError();
let promises: wp.Promise = wp.Promise.all([
pool.exec('foo', null),
pool.exec('foo', null),
pool.exec('foo', null)
]);
promises = wp.Promise.all([]);
pool.exec(hello, [])
.then((s: string) => s);
const workers = {add, hello};
type IWorkers = typeof workers;
pool.proxy().then((proxy) => {
proxy.add(1, 2);
proxy.hello();
});
pool.proxy().then((proxy) => {
proxy.add(1, 2);
proxy.hello();
});
new wp.Promise.CancellationError();
new wp.Promise.TimeoutError();
let promises: wp.Promise = wp.Promise.all([
pool.exec('foo', null),
pool.exec('foo', null),
pool.exec('foo', null)
]);
promises = wp.Promise.all([]);
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(