flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
21
BACK_BACK/node_modules/@parcel/workers/LICENSE
generated
vendored
Executable file
21
BACK_BACK/node_modules/@parcel/workers/LICENSE
generated
vendored
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017-present Devon Govett
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
5
BACK_BACK/node_modules/@parcel/workers/index.js
generated
vendored
Executable file
5
BACK_BACK/node_modules/@parcel/workers/index.js
generated
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
// Node 8 supports native async functions - no need to use compiled code!
|
||||
module.exports =
|
||||
parseInt(process.versions.node, 10) < 8
|
||||
? require('./lib/WorkerFarm')
|
||||
: require('./src/WorkerFarm');
|
||||
33
BACK_BACK/node_modules/@parcel/workers/package.json
generated
vendored
Executable file
33
BACK_BACK/node_modules/@parcel/workers/package.json
generated
vendored
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "@parcel/workers",
|
||||
"version": "1.11.0",
|
||||
"description": "Blazing fast, zero configuration web application bundler",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/parcel-bundler/parcel.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "cross-env NODE_ENV=test mocha",
|
||||
"test-ci": "yarn build && yarn test",
|
||||
"format": "prettier --write \"./{src,bin,test}/**/*.{js,json,md}\"",
|
||||
"lint": "eslint . && prettier \"./{src,bin,test}/**/*.{js,json,md}\" --list-different",
|
||||
"build": "babel src -d lib",
|
||||
"prepublish": "yarn build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^5.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@parcel/utils": "^1.11.0",
|
||||
"physical-cpu-count": "^2.0.0"
|
||||
},
|
||||
"gitHead": "34eb91e8e6991073e594bff731c333d09b0403b5"
|
||||
}
|
||||
8
BACK_BACK/node_modules/@parcel/workers/src/.babelrc
generated
vendored
Executable file
8
BACK_BACK/node_modules/@parcel/workers/src/.babelrc
generated
vendored
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"presets": [["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "6"
|
||||
}
|
||||
}]],
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
||||
3
BACK_BACK/node_modules/@parcel/workers/src/.eslintrc.json
generated
vendored
Executable file
3
BACK_BACK/node_modules/@parcel/workers/src/.eslintrc.json
generated
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": "../../../../.eslintrc.json"
|
||||
}
|
||||
176
BACK_BACK/node_modules/@parcel/workers/src/Worker.js
generated
vendored
Executable file
176
BACK_BACK/node_modules/@parcel/workers/src/Worker.js
generated
vendored
Executable file
|
|
@ -0,0 +1,176 @@
|
|||
const childProcess = require('child_process');
|
||||
const {EventEmitter} = require('events');
|
||||
const {errorUtils} = require('@parcel/utils');
|
||||
|
||||
const childModule = require.resolve('./child');
|
||||
|
||||
let WORKER_ID = 0;
|
||||
class Worker extends EventEmitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
|
||||
this.options = options;
|
||||
this.id = WORKER_ID++;
|
||||
|
||||
this.sendQueue = [];
|
||||
this.processQueue = true;
|
||||
|
||||
this.calls = new Map();
|
||||
this.exitCode = null;
|
||||
this.callId = 0;
|
||||
|
||||
this.ready = false;
|
||||
this.stopped = false;
|
||||
this.isStopping = false;
|
||||
}
|
||||
|
||||
async fork(forkModule, bundlerOptions) {
|
||||
let filteredArgs = process.execArgv.filter(
|
||||
v => !/^--(debug|inspect)/.test(v)
|
||||
);
|
||||
|
||||
let options = {
|
||||
execArgv: filteredArgs,
|
||||
env: process.env,
|
||||
cwd: process.cwd()
|
||||
};
|
||||
|
||||
this.child = childProcess.fork(childModule, process.argv, options);
|
||||
|
||||
this.child.on('message', data => this.receive(data));
|
||||
|
||||
this.child.once('exit', code => {
|
||||
this.exitCode = code;
|
||||
this.emit('exit', code);
|
||||
});
|
||||
|
||||
this.child.on('error', err => {
|
||||
this.emit('error', err);
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
this.call({
|
||||
method: 'childInit',
|
||||
args: [forkModule],
|
||||
retries: 0,
|
||||
resolve,
|
||||
reject
|
||||
});
|
||||
});
|
||||
|
||||
await this.init(bundlerOptions);
|
||||
}
|
||||
|
||||
async init(bundlerOptions) {
|
||||
this.ready = false;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.call({
|
||||
method: 'init',
|
||||
args: [bundlerOptions],
|
||||
retries: 0,
|
||||
resolve: (...args) => {
|
||||
this.ready = true;
|
||||
this.emit('ready');
|
||||
resolve(...args);
|
||||
},
|
||||
reject
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
send(data) {
|
||||
if (!this.processQueue) {
|
||||
return this.sendQueue.push(data);
|
||||
}
|
||||
|
||||
let result = this.child.send(data, error => {
|
||||
if (error && error instanceof Error) {
|
||||
// Ignore this, the workerfarm handles child errors
|
||||
return;
|
||||
}
|
||||
|
||||
this.processQueue = true;
|
||||
|
||||
if (this.sendQueue.length > 0) {
|
||||
let queueCopy = this.sendQueue.slice(0);
|
||||
this.sendQueue = [];
|
||||
queueCopy.forEach(entry => this.send(entry));
|
||||
}
|
||||
});
|
||||
|
||||
if (!result || /^win/.test(process.platform)) {
|
||||
// Queue is handling too much messages throttle it
|
||||
this.processQueue = false;
|
||||
}
|
||||
}
|
||||
|
||||
call(call) {
|
||||
if (this.stopped || this.isStopping) {
|
||||
return;
|
||||
}
|
||||
|
||||
let idx = this.callId++;
|
||||
this.calls.set(idx, call);
|
||||
|
||||
this.send({
|
||||
type: 'request',
|
||||
idx: idx,
|
||||
child: this.id,
|
||||
method: call.method,
|
||||
args: call.args
|
||||
});
|
||||
}
|
||||
|
||||
receive(data) {
|
||||
if (this.stopped || this.isStopping) {
|
||||
return;
|
||||
}
|
||||
|
||||
let idx = data.idx;
|
||||
let type = data.type;
|
||||
let content = data.content;
|
||||
let contentType = data.contentType;
|
||||
|
||||
if (type === 'request') {
|
||||
this.emit('request', data);
|
||||
} else if (type === 'response') {
|
||||
let call = this.calls.get(idx);
|
||||
if (!call) {
|
||||
// Return for unknown calls, these might accur if a third party process uses workers
|
||||
return;
|
||||
}
|
||||
|
||||
if (contentType === 'error') {
|
||||
call.reject(errorUtils.jsonToError(content));
|
||||
} else {
|
||||
call.resolve(content);
|
||||
}
|
||||
|
||||
this.calls.delete(idx);
|
||||
this.emit('response', data);
|
||||
}
|
||||
}
|
||||
|
||||
async stop() {
|
||||
if (!this.stopped) {
|
||||
this.stopped = true;
|
||||
|
||||
if (this.child) {
|
||||
this.child.send('die');
|
||||
|
||||
let forceKill = setTimeout(
|
||||
() => this.child.kill('SIGINT'),
|
||||
this.options.forcedKillTime
|
||||
);
|
||||
await new Promise(resolve => {
|
||||
this.child.once('exit', resolve);
|
||||
});
|
||||
|
||||
clearTimeout(forceKill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Worker;
|
||||
300
BACK_BACK/node_modules/@parcel/workers/src/WorkerFarm.js
generated
vendored
Executable file
300
BACK_BACK/node_modules/@parcel/workers/src/WorkerFarm.js
generated
vendored
Executable file
|
|
@ -0,0 +1,300 @@
|
|||
const {EventEmitter} = require('events');
|
||||
const {errorUtils} = require('@parcel/utils');
|
||||
const Worker = require('./Worker');
|
||||
const cpuCount = require('./cpuCount');
|
||||
|
||||
let shared = null;
|
||||
|
||||
/**
|
||||
* workerPath should always be defined inside farmOptions
|
||||
*/
|
||||
|
||||
class WorkerFarm extends EventEmitter {
|
||||
constructor(options, farmOptions = {}) {
|
||||
super();
|
||||
this.options = {
|
||||
maxConcurrentWorkers: WorkerFarm.getNumWorkers(),
|
||||
maxConcurrentCallsPerWorker: WorkerFarm.getConcurrentCallsPerWorker(),
|
||||
forcedKillTime: 500,
|
||||
warmWorkers: true,
|
||||
useLocalWorker: true
|
||||
};
|
||||
|
||||
if (farmOptions) {
|
||||
this.options = Object.assign(this.options, farmOptions);
|
||||
}
|
||||
|
||||
this.warmWorkers = 0;
|
||||
this.workers = new Map();
|
||||
this.callQueue = [];
|
||||
|
||||
if (!this.options.workerPath) {
|
||||
throw new Error('Please provide a worker path!');
|
||||
}
|
||||
|
||||
this.localWorker = require(this.options.workerPath);
|
||||
this.run = this.mkhandle('run');
|
||||
|
||||
this.init(options);
|
||||
}
|
||||
|
||||
warmupWorker(method, args) {
|
||||
// Workers are already stopping
|
||||
if (this.ending) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Workers are not warmed up yet.
|
||||
// Send the job to a remote worker in the background,
|
||||
// but use the result from the local worker - it will be faster.
|
||||
let promise = this.addCall(method, [...args, true]);
|
||||
if (promise) {
|
||||
promise
|
||||
.then(() => {
|
||||
this.warmWorkers++;
|
||||
if (this.warmWorkers >= this.workers.size) {
|
||||
this.emit('warmedup');
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
shouldStartRemoteWorkers() {
|
||||
return (
|
||||
this.options.maxConcurrentWorkers > 1 ||
|
||||
process.env.NODE_ENV === 'test' ||
|
||||
!this.options.useLocalWorker
|
||||
);
|
||||
}
|
||||
|
||||
mkhandle(method) {
|
||||
return (...args) => {
|
||||
// Child process workers are slow to start (~600ms).
|
||||
// While we're waiting, just run on the main thread.
|
||||
// This significantly speeds up startup time.
|
||||
if (this.shouldUseRemoteWorkers()) {
|
||||
return this.addCall(method, [...args, false]);
|
||||
} else {
|
||||
if (this.options.warmWorkers && this.shouldStartRemoteWorkers()) {
|
||||
this.warmupWorker(method, args);
|
||||
}
|
||||
|
||||
return this.localWorker[method](...args, false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
onError(error, worker) {
|
||||
// Handle ipc errors
|
||||
if (error.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
||||
return this.stopWorker(worker);
|
||||
}
|
||||
}
|
||||
|
||||
startChild() {
|
||||
let worker = new Worker(this.options);
|
||||
|
||||
worker.fork(this.options.workerPath, this.bundlerOptions);
|
||||
|
||||
worker.on('request', data => this.processRequest(data, worker));
|
||||
|
||||
worker.on('ready', () => this.processQueue());
|
||||
worker.on('response', () => this.processQueue());
|
||||
|
||||
worker.on('error', err => this.onError(err, worker));
|
||||
worker.once('exit', () => this.stopWorker(worker));
|
||||
|
||||
this.workers.set(worker.id, worker);
|
||||
}
|
||||
|
||||
async stopWorker(worker) {
|
||||
if (!worker.stopped) {
|
||||
this.workers.delete(worker.id);
|
||||
|
||||
worker.isStopping = true;
|
||||
|
||||
if (worker.calls.size) {
|
||||
for (let call of worker.calls.values()) {
|
||||
call.retries++;
|
||||
this.callQueue.unshift(call);
|
||||
}
|
||||
}
|
||||
|
||||
worker.calls = null;
|
||||
|
||||
await worker.stop();
|
||||
|
||||
// Process any requests that failed and start a new worker
|
||||
this.processQueue();
|
||||
}
|
||||
}
|
||||
|
||||
async processQueue() {
|
||||
if (this.ending || !this.callQueue.length) return;
|
||||
|
||||
if (this.workers.size < this.options.maxConcurrentWorkers) {
|
||||
this.startChild();
|
||||
}
|
||||
|
||||
for (let worker of this.workers.values()) {
|
||||
if (!this.callQueue.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!worker.ready || worker.stopped || worker.isStopping) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (worker.calls.size < this.options.maxConcurrentCallsPerWorker) {
|
||||
worker.call(this.callQueue.shift());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async processRequest(data, worker = false) {
|
||||
let result = {
|
||||
idx: data.idx,
|
||||
type: 'response'
|
||||
};
|
||||
|
||||
let method = data.method;
|
||||
let args = data.args;
|
||||
let location = data.location;
|
||||
let awaitResponse = data.awaitResponse;
|
||||
|
||||
if (!location) {
|
||||
throw new Error('Unknown request');
|
||||
}
|
||||
|
||||
const mod = require(location);
|
||||
try {
|
||||
result.contentType = 'data';
|
||||
if (method) {
|
||||
result.content = await mod[method](...args);
|
||||
} else {
|
||||
result.content = await mod(...args);
|
||||
}
|
||||
} catch (e) {
|
||||
result.contentType = 'error';
|
||||
result.content = errorUtils.errorToJson(e);
|
||||
}
|
||||
|
||||
if (awaitResponse) {
|
||||
if (worker) {
|
||||
worker.send(result);
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addCall(method, args) {
|
||||
if (this.ending) {
|
||||
throw new Error('Cannot add a worker call if workerfarm is ending.');
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.callQueue.push({
|
||||
method,
|
||||
args: args,
|
||||
retries: 0,
|
||||
resolve,
|
||||
reject
|
||||
});
|
||||
this.processQueue();
|
||||
});
|
||||
}
|
||||
|
||||
async end() {
|
||||
this.ending = true;
|
||||
await Promise.all(
|
||||
Array.from(this.workers.values()).map(worker => this.stopWorker(worker))
|
||||
);
|
||||
this.ending = false;
|
||||
shared = null;
|
||||
}
|
||||
|
||||
init(bundlerOptions) {
|
||||
this.bundlerOptions = bundlerOptions;
|
||||
|
||||
if (this.shouldStartRemoteWorkers()) {
|
||||
this.persistBundlerOptions();
|
||||
}
|
||||
|
||||
this.localWorker.init(bundlerOptions);
|
||||
this.startMaxWorkers();
|
||||
}
|
||||
|
||||
persistBundlerOptions() {
|
||||
for (let worker of this.workers.values()) {
|
||||
worker.init(this.bundlerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
startMaxWorkers() {
|
||||
// Starts workers untill the maximum is reached
|
||||
if (this.workers.size < this.options.maxConcurrentWorkers) {
|
||||
for (
|
||||
let i = 0;
|
||||
i < this.options.maxConcurrentWorkers - this.workers.size;
|
||||
i++
|
||||
) {
|
||||
this.startChild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shouldUseRemoteWorkers() {
|
||||
return (
|
||||
!this.options.useLocalWorker ||
|
||||
(this.warmWorkers >= this.workers.size || !this.options.warmWorkers)
|
||||
);
|
||||
}
|
||||
|
||||
static async getShared(options, farmOptions) {
|
||||
// Farm options shouldn't be considered safe to overwrite
|
||||
// and require an entire new instance to be created
|
||||
if (shared && farmOptions) {
|
||||
await shared.end();
|
||||
shared = null;
|
||||
}
|
||||
|
||||
if (!shared) {
|
||||
shared = new WorkerFarm(options, farmOptions);
|
||||
} else if (options) {
|
||||
shared.init(options);
|
||||
}
|
||||
|
||||
if (!shared && !options) {
|
||||
throw new Error('Workerfarm should be initialised using options');
|
||||
}
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
static getNumWorkers() {
|
||||
return process.env.PARCEL_WORKERS
|
||||
? parseInt(process.env.PARCEL_WORKERS, 10)
|
||||
: cpuCount();
|
||||
}
|
||||
|
||||
static async callMaster(request, awaitResponse = true) {
|
||||
if (WorkerFarm.isWorker()) {
|
||||
const child = require('./child');
|
||||
return child.addCall(request, awaitResponse);
|
||||
} else {
|
||||
return (await WorkerFarm.getShared()).processRequest(request);
|
||||
}
|
||||
}
|
||||
|
||||
static isWorker() {
|
||||
return process.send && require.main.filename === require.resolve('./child');
|
||||
}
|
||||
|
||||
static getConcurrentCallsPerWorker() {
|
||||
return parseInt(process.env.PARCEL_MAX_CONCURRENT_CALLS, 10) || 5;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WorkerFarm;
|
||||
144
BACK_BACK/node_modules/@parcel/workers/src/child.js
generated
vendored
Executable file
144
BACK_BACK/node_modules/@parcel/workers/src/child.js
generated
vendored
Executable file
|
|
@ -0,0 +1,144 @@
|
|||
const {errorUtils} = require('@parcel/utils');
|
||||
|
||||
class Child {
|
||||
constructor() {
|
||||
if (!process.send) {
|
||||
throw new Error('Only create Child instances in a worker!');
|
||||
}
|
||||
|
||||
this.module = undefined;
|
||||
this.childId = undefined;
|
||||
|
||||
this.callQueue = [];
|
||||
this.responseQueue = new Map();
|
||||
this.responseId = 0;
|
||||
this.maxConcurrentCalls = 10;
|
||||
}
|
||||
|
||||
messageListener(data) {
|
||||
if (data === 'die') {
|
||||
return this.end();
|
||||
}
|
||||
|
||||
let type = data.type;
|
||||
if (type === 'response') {
|
||||
return this.handleResponse(data);
|
||||
} else if (type === 'request') {
|
||||
return this.handleRequest(data);
|
||||
}
|
||||
}
|
||||
|
||||
async send(data) {
|
||||
process.send(data, err => {
|
||||
if (err && err instanceof Error) {
|
||||
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
||||
// IPC connection closed
|
||||
// no need to keep the worker running if it can't send or receive data
|
||||
return this.end();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
childInit(module, childId) {
|
||||
this.module = require(module);
|
||||
this.childId = childId;
|
||||
}
|
||||
|
||||
async handleRequest(data) {
|
||||
let idx = data.idx;
|
||||
let child = data.child;
|
||||
let method = data.method;
|
||||
let args = data.args;
|
||||
|
||||
let result = {idx, child, type: 'response'};
|
||||
try {
|
||||
result.contentType = 'data';
|
||||
if (method === 'childInit') {
|
||||
result.content = this.childInit(...args, child);
|
||||
} else {
|
||||
result.content = await this.module[method](...args);
|
||||
}
|
||||
} catch (e) {
|
||||
result.contentType = 'error';
|
||||
result.content = errorUtils.errorToJson(e);
|
||||
}
|
||||
|
||||
this.send(result);
|
||||
}
|
||||
|
||||
async handleResponse(data) {
|
||||
let idx = data.idx;
|
||||
let contentType = data.contentType;
|
||||
let content = data.content;
|
||||
let call = this.responseQueue.get(idx);
|
||||
|
||||
if (contentType === 'error') {
|
||||
call.reject(errorUtils.jsonToError(content));
|
||||
} else {
|
||||
call.resolve(content);
|
||||
}
|
||||
|
||||
this.responseQueue.delete(idx);
|
||||
|
||||
// Process the next call
|
||||
this.processQueue();
|
||||
}
|
||||
|
||||
// Keep in mind to make sure responses to these calls are JSON.Stringify safe
|
||||
async addCall(request, awaitResponse = true) {
|
||||
let call = request;
|
||||
call.type = 'request';
|
||||
call.child = this.childId;
|
||||
call.awaitResponse = awaitResponse;
|
||||
|
||||
let promise;
|
||||
if (awaitResponse) {
|
||||
promise = new Promise((resolve, reject) => {
|
||||
call.resolve = resolve;
|
||||
call.reject = reject;
|
||||
});
|
||||
}
|
||||
|
||||
this.callQueue.push(call);
|
||||
this.processQueue();
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
async sendRequest(call) {
|
||||
let idx;
|
||||
if (call.awaitResponse) {
|
||||
idx = this.responseId++;
|
||||
this.responseQueue.set(idx, call);
|
||||
}
|
||||
this.send({
|
||||
idx: idx,
|
||||
child: call.child,
|
||||
type: call.type,
|
||||
location: call.location,
|
||||
method: call.method,
|
||||
args: call.args,
|
||||
awaitResponse: call.awaitResponse
|
||||
});
|
||||
}
|
||||
|
||||
async processQueue() {
|
||||
if (!this.callQueue.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.responseQueue.size < this.maxConcurrentCalls) {
|
||||
this.sendRequest(this.callQueue.shift());
|
||||
}
|
||||
}
|
||||
|
||||
end() {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
let child = new Child();
|
||||
process.on('message', child.messageListener.bind(child));
|
||||
|
||||
module.exports = child;
|
||||
11
BACK_BACK/node_modules/@parcel/workers/src/cpuCount.js
generated
vendored
Executable file
11
BACK_BACK/node_modules/@parcel/workers/src/cpuCount.js
generated
vendored
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
const os = require('os');
|
||||
|
||||
module.exports = function() {
|
||||
let cores;
|
||||
try {
|
||||
cores = require('physical-cpu-count');
|
||||
} catch (err) {
|
||||
cores = os.cpus().length;
|
||||
}
|
||||
return cores || 1;
|
||||
};
|
||||
9
BACK_BACK/node_modules/@parcel/workers/test/.babelrc
generated
vendored
Executable file
9
BACK_BACK/node_modules/@parcel/workers/test/.babelrc
generated
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"presets": [["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}]],
|
||||
"plugins": ["@babel/plugin-transform-runtime"],
|
||||
"ignore": ["integration"]
|
||||
}
|
||||
6
BACK_BACK/node_modules/@parcel/workers/test/.eslintrc.json
generated
vendored
Executable file
6
BACK_BACK/node_modules/@parcel/workers/test/.eslintrc.json
generated
vendored
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extends": "../../../../.eslintrc.json",
|
||||
"env": {
|
||||
"mocha": true
|
||||
}
|
||||
}
|
||||
10
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/echo.js
generated
vendored
Executable file
10
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/echo.js
generated
vendored
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
function run(data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
function init() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
exports.run = run;
|
||||
exports.init = init;
|
||||
12
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/init.js
generated
vendored
Executable file
12
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/init.js
generated
vendored
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
let options = {};
|
||||
|
||||
function run() {
|
||||
return options;
|
||||
}
|
||||
|
||||
function init(opt) {
|
||||
options = opt;
|
||||
}
|
||||
|
||||
exports.run = run;
|
||||
exports.init = init;
|
||||
25
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/ipc-pid.js
generated
vendored
Executable file
25
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/ipc-pid.js
generated
vendored
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
const WorkerFarm = require(`../../../${
|
||||
parseInt(process.versions.node, 10) < 8 ? 'lib' : 'src'
|
||||
}/WorkerFarm`);
|
||||
|
||||
function run() {
|
||||
let result = [process.pid];
|
||||
return new Promise((resolve, reject) => {
|
||||
WorkerFarm.callMaster({
|
||||
location: require.resolve('./master-process-id.js'),
|
||||
args: []
|
||||
})
|
||||
.then(pid => {
|
||||
result.push(pid);
|
||||
resolve(result);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
exports.run = run;
|
||||
exports.init = init;
|
||||
17
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/ipc.js
generated
vendored
Executable file
17
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/ipc.js
generated
vendored
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
const WorkerFarm = require(`../../../${
|
||||
parseInt(process.versions.node, 10) < 8 ? 'lib' : 'src'
|
||||
}/WorkerFarm`);
|
||||
|
||||
function run(a, b) {
|
||||
return WorkerFarm.callMaster({
|
||||
location: require.resolve('./master-sum.js'),
|
||||
args: [a, b]
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
exports.run = run;
|
||||
exports.init = init;
|
||||
3
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/master-process-id.js
generated
vendored
Executable file
3
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/master-process-id.js
generated
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function() {
|
||||
return process.pid;
|
||||
};
|
||||
3
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/master-sum.js
generated
vendored
Executable file
3
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/master-sum.js
generated
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function(a, b) {
|
||||
return a + b;
|
||||
};
|
||||
10
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/ping.js
generated
vendored
Executable file
10
BACK_BACK/node_modules/@parcel/workers/test/integration/workerfarm/ping.js
generated
vendored
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
function run() {
|
||||
return 'pong';
|
||||
}
|
||||
|
||||
function init() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
exports.run = run;
|
||||
exports.init = init;
|
||||
3
BACK_BACK/node_modules/@parcel/workers/test/mocha.opts
generated
vendored
Executable file
3
BACK_BACK/node_modules/@parcel/workers/test/mocha.opts
generated
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
--require @parcel/babel-register
|
||||
--exit
|
||||
--timeout 20s
|
||||
178
BACK_BACK/node_modules/@parcel/workers/test/workerfarm.js
generated
vendored
Executable file
178
BACK_BACK/node_modules/@parcel/workers/test/workerfarm.js
generated
vendored
Executable file
|
|
@ -0,0 +1,178 @@
|
|||
const assert = require('assert');
|
||||
const WorkerFarm = require('../index');
|
||||
|
||||
describe('WorkerFarm', () => {
|
||||
it('Should start up workers', async () => {
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: false,
|
||||
useLocalWorker: false,
|
||||
workerPath: require.resolve('./integration/workerfarm/ping.js')
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(await workerfarm.run(), 'pong');
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Should handle 1000 requests without any issue', async () => {
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: false,
|
||||
useLocalWorker: false,
|
||||
workerPath: require.resolve('./integration/workerfarm/echo.js')
|
||||
}
|
||||
);
|
||||
|
||||
let promises = [];
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
promises.push(workerfarm.run(i));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Should consistently initialise workers, even after 100 re-inits', async () => {
|
||||
let options = {
|
||||
key: 0
|
||||
};
|
||||
|
||||
let workerfarm = new WorkerFarm(options, {
|
||||
warmWorkers: false,
|
||||
useLocalWorker: false,
|
||||
workerPath: require.resolve('./integration/workerfarm/init.js')
|
||||
});
|
||||
|
||||
for (let i = 0; i < 100; i++) {
|
||||
options.key = i;
|
||||
workerfarm.init(options);
|
||||
|
||||
for (let i = 0; i < workerfarm.workers.size; i++) {
|
||||
assert.equal((await workerfarm.run()).key, options.key);
|
||||
}
|
||||
assert.equal(workerfarm.shouldUseRemoteWorkers(), true);
|
||||
}
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Should warm up workers', async () => {
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: true,
|
||||
useLocalWorker: true,
|
||||
workerPath: require.resolve('./integration/workerfarm/echo.js')
|
||||
}
|
||||
);
|
||||
|
||||
for (let i = 0; i < 100; i++) {
|
||||
assert.equal(await workerfarm.run(i), i);
|
||||
}
|
||||
|
||||
await new Promise(resolve => workerfarm.once('warmedup', resolve));
|
||||
|
||||
assert(workerfarm.workers.size > 0, 'Should have spawned workers.');
|
||||
assert(
|
||||
workerfarm.warmWorkers >= workerfarm.workers.size,
|
||||
'Should have warmed up workers.'
|
||||
);
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Should use the local worker', async () => {
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: true,
|
||||
useLocalWorker: true,
|
||||
workerPath: require.resolve('./integration/workerfarm/echo.js')
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(await workerfarm.run('hello world'), 'hello world');
|
||||
assert.equal(workerfarm.shouldUseRemoteWorkers(), false);
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Should be able to use bi-directional communication', async () => {
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: false,
|
||||
useLocalWorker: false,
|
||||
workerPath: require.resolve('./integration/workerfarm/ipc.js')
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(await workerfarm.run(1, 2), 3);
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Should be able to handle 1000 bi-directional calls', async () => {
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: false,
|
||||
useLocalWorker: false,
|
||||
workerPath: require.resolve('./integration/workerfarm/ipc.js')
|
||||
}
|
||||
);
|
||||
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
assert.equal(await workerfarm.run(1 + i, 2), 3 + i);
|
||||
}
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Bi-directional call should return masters pid', async () => {
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: false,
|
||||
useLocalWorker: false,
|
||||
workerPath: require.resolve('./integration/workerfarm/ipc-pid.js')
|
||||
}
|
||||
);
|
||||
|
||||
let result = await workerfarm.run();
|
||||
assert.equal(result.length, 2);
|
||||
assert.equal(result[1], process.pid);
|
||||
assert.notEqual(result[0], process.pid);
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
|
||||
it('Should handle 10 big concurrent requests without any issue', async () => {
|
||||
// This emulates the node.js ipc bug for win32
|
||||
let workerfarm = new WorkerFarm(
|
||||
{},
|
||||
{
|
||||
warmWorkers: false,
|
||||
useLocalWorker: false,
|
||||
workerPath: require.resolve('./integration/workerfarm/echo.js')
|
||||
}
|
||||
);
|
||||
|
||||
let bigData = [];
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
bigData.push('This is some big data');
|
||||
}
|
||||
|
||||
let promises = [];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
promises.push(workerfarm.run(bigData));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
|
||||
await workerfarm.end();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue