Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

poolifier

Package Overview
Dependencies
Maintainers
1
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

poolifier - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

7

CHANGELOG.md

@@ -8,2 +8,9 @@ # Changelog

## [2.0.1] - 2021-16-03
### Bug fixes
- Check if pool options are properly set.
- `busy` event is emitted on all pool types.
## [2.0.0] - 2021-01-03

@@ -10,0 +17,0 @@

2

lib/index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("cluster"),r=require("events"),t=require("worker_threads"),s=require("async_hooks");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(r);const n=Object.freeze({SOFT:"SOFT",HARD:"HARD"});class a extends i.default{}const h=Object.freeze({ROUND_ROBIN:"ROUND_ROBIN",LESS_RECENTLY_USED:"LESS_RECENTLY_USED"});class c{constructor(e){this.pool=e,this.nextWorkerIndex=0}choose(){const e=this.pool.workers[this.nextWorkerIndex];return this.nextWorkerIndex=this.pool.workers.length-1===this.nextWorkerIndex?0:this.nextWorkerIndex+1,e}}class k{constructor(e){this.pool=e}choose(){const e=this.pool.dynamic;let r,t=1/0;for(const[s,o]of this.pool.tasks){if(!e&&0===o)return s;o<t&&(t=o,r=s)}return r}}class l{constructor(e,r,t=h.ROUND_ROBIN){this.pool=e,this.createDynamicallyWorkerCallback=r,this.workerChoiceStrategy=d.getWorkerChoiceStrategy(this.pool,t)}choose(){const e=d.findFreeWorkerBasedOnTasks(this.pool.tasks);return e||(this.pool.workers.length===this.pool.max?(this.pool.emitter.emit("busy"),this.workerChoiceStrategy.choose()):this.createDynamicallyWorkerCallback())}}class u{constructor(e,r,t=h.ROUND_ROBIN){this.pool=e,this.createDynamicallyWorkerCallback=r,this.setWorkerChoiceStrategy(t)}getPoolWorkerChoiceStrategy(e=h.ROUND_ROBIN){return this.pool.dynamic?new l(this.pool,this.createDynamicallyWorkerCallback,e):d.getWorkerChoiceStrategy(this.pool,e)}setWorkerChoiceStrategy(e){this.workerChoiceStrategy=this.getPoolWorkerChoiceStrategy(e)}execute(){return this.workerChoiceStrategy.choose()}}class d{static findFreeWorkerBasedOnTasks(e){for(const[r,t]of e)if(0===t)return r;return null}static getWorkerChoiceStrategy(e,r=h.ROUND_ROBIN){switch(r){case h.ROUND_ROBIN:return new c(e);case h.LESS_RECENTLY_USED:return new k(e);default:throw new Error(`Worker choice strategy '${r}' not found`)}}}const p=()=>{};class W{constructor(e,r,t){var s;if(this.numberOfWorkers=e,this.filePath=r,this.opts=t,this.workers=[],this.tasks=new Map,this.promiseMap=new Map,this.nextMessageId=0,!this.isMain())throw new Error("Cannot start a pool from a worker!");this.checkNumberOfWorkers(this.numberOfWorkers),this.checkFilePath(this.filePath),this.setupHook();for(let e=1;e<=this.numberOfWorkers;e++)this.createAndSetupWorker();this.emitter=new a,this.workerChoiceStrategyContext=new u(this,(()=>{const e=this.createAndSetupWorker();return this.registerWorkerMessageListener(e,(r=>{const t=this.tasks.get(e);var s;s=n.HARD,(r.kill===s||0===t)&&this.destroyWorker(e)})),e}),null!==(s=t.workerChoiceStrategy)&&void 0!==s?s:h.ROUND_ROBIN)}checkFilePath(e){if(!e)throw new Error("Please specify a file with a worker implementation")}checkNumberOfWorkers(e){if(null==e)throw new Error("Cannot instantiate a pool without specifying the number of workers");if(!Number.isSafeInteger(e))throw new Error("Cannot instantiate a pool with a non integer number of workers");if(e<0)throw new Error("Cannot instantiate a pool with a negative number of workers");if(!this.dynamic&&0===e)throw new Error("Cannot instantiate a fixed pool with no worker")}get dynamic(){return!1}setWorkerChoiceStrategy(e){this.opts.workerChoiceStrategy=e,this.workerChoiceStrategyContext.setWorkerChoiceStrategy(e)}execute(e){const r=this.chooseWorker();this.increaseWorkersTask(r);const t=++this.nextMessageId,s=this.internalExecute(r,t);return this.sendToWorker(r,{data:e||{},id:t}),s}async destroy(){await Promise.all(this.workers.map((e=>this.destroyWorker(e))))}setupHook(){}increaseWorkersTask(e){this.stepWorkerNumberOfTasks(e,1)}decreaseWorkersTasks(e){this.stepWorkerNumberOfTasks(e,-1)}stepWorkerNumberOfTasks(e,r){const t=this.tasks.get(e);if(void 0===t)throw Error("Worker could not be found in tasks map");this.tasks.set(e,t+r)}removeWorker(e){const r=this.workers.indexOf(e);this.workers.splice(r,1),this.tasks.delete(e)}chooseWorker(){return this.workerChoiceStrategyContext.execute()}internalExecute(e,r){return new Promise(((t,s)=>{this.promiseMap.set(r,{resolve:t,reject:s,worker:e})}))}createAndSetupWorker(){var e,r,t;const s=this.createWorker();return s.on("error",null!==(e=this.opts.errorHandler)&&void 0!==e?e:p),s.on("online",null!==(r=this.opts.onlineHandler)&&void 0!==r?r:p),s.on("exit",null!==(t=this.opts.exitHandler)&&void 0!==t?t:p),s.once("exit",(()=>this.removeWorker(s))),this.workers.push(s),this.tasks.set(s,0),this.afterWorkerSetup(s),s}workerListener(){return e=>{if(e.id){const r=this.promiseMap.get(e.id);r&&(this.decreaseWorkersTasks(r.worker),e.error?r.reject(e.error):r.resolve(e.data),this.promiseMap.delete(e.id))}}}}class w extends W{constructor(e,r,t={}){super(e,r,t),this.opts=t}setupHook(){e.setupMaster({exec:this.filePath})}isMain(){return e.isMaster}destroyWorker(e){this.sendToWorker(e,{kill:1}),e.kill()}sendToWorker(e,r){e.send(r)}registerWorkerMessageListener(e,r){e.on("message",r)}createWorker(){return e.fork(this.opts.env)}afterWorkerSetup(e){this.registerWorkerMessageListener(e,super.workerListener())}}class m extends W{constructor(e,r,t={}){super(e,r,t)}isMain(){return t.isMainThread}async destroyWorker(e){this.sendToWorker(e,{kill:1}),await e.terminate()}sendToWorker(e,r){e.postMessage(r)}registerWorkerMessageListener(e,r){var t;null===(t=e.port2)||void 0===t||t.on("message",r)}createWorker(){return new t.Worker(this.filePath,{env:t.SHARE_ENV})}afterWorkerSetup(e){const{port1:r,port2:s}=new t.MessageChannel;e.postMessage({parent:r},[r]),e.port1=r,e.port2=s,this.registerWorkerMessageListener(e,super.workerListener())}}const g=n.SOFT;class y extends s.AsyncResource{constructor(e,r,t,s,o={killBehavior:g,maxInactiveTime:6e4}){var i,n,a;super(e),this.mainWorker=s,this.opts=o,this.killBehavior=null!==(i=this.opts.killBehavior)&&void 0!==i?i:g,this.maxInactiveTime=null!==(n=this.opts.maxInactiveTime)&&void 0!==n?n:6e4,this.async=!!this.opts.async,this.lastTask=Date.now(),this.checkFunctionInput(t),r||(this.interval=setInterval(this.checkAlive.bind(this),this.maxInactiveTime/2),this.checkAlive.bind(this)()),null===(a=this.mainWorker)||void 0===a||a.on("message",(e=>{(null==e?void 0:e.data)&&e.id?this.async?this.runInAsyncScope(this.runAsync.bind(this),this,t,e):this.runInAsyncScope(this.run.bind(this),this,t,e):e.parent?this.mainWorker=e.parent:e.kill&&(this.interval&&clearInterval(this.interval),this.emitDestroy())}))}checkFunctionInput(e){if(!e)throw new Error("fn parameter is mandatory")}getMainWorker(){if(!this.mainWorker)throw new Error("Main worker was not set");return this.mainWorker}checkAlive(){Date.now()-this.lastTask>this.maxInactiveTime&&this.sendToMainWorker({kill:this.killBehavior})}handleError(e){return e}run(e,r){try{const t=e(r.data);this.sendToMainWorker({data:t,id:r.id}),this.lastTask=Date.now()}catch(e){const t=this.handleError(e);this.sendToMainWorker({error:t,id:r.id}),this.lastTask=Date.now()}}runAsync(e,r){e(r.data).then((e=>(this.sendToMainWorker({data:e,id:r.id}),this.lastTask=Date.now(),null))).catch((e=>{const t=this.handleError(e);this.sendToMainWorker({error:t,id:r.id}),this.lastTask=Date.now()}))}}exports.AbstractWorker=y,exports.ClusterWorker=class extends y{constructor(r,t={}){super("worker-cluster-pool:pioardi",e.isMaster,r,e.worker,t)}sendToMainWorker(e){this.getMainWorker().send(e)}handleError(e){return e instanceof Error?e.message:e}},exports.DynamicClusterPool=class extends w{constructor(e,r,t,s={}){super(e,t,s),this.max=r}get dynamic(){return!0}},exports.DynamicThreadPool=class extends m{constructor(e,r,t,s={}){super(e,t,s),this.max=r}get dynamic(){return!0}},exports.FixedClusterPool=w,exports.FixedThreadPool=m,exports.KillBehaviors=n,exports.ThreadWorker=class extends y{constructor(e,r={}){super("worker-thread-pool:pioardi",t.isMainThread,e,t.parentPort,r)}sendToMainWorker(e){this.getMainWorker().postMessage(e)}},exports.WorkerChoiceStrategies=h;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("events"),t=require("cluster"),r=require("worker_threads"),s=require("async_hooks");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i,n=o(e);!function(e){e.FIXED="fixed",e.DYNAMIC="dynamic"}(i||(i={}));class a extends n.default{}const h=Object.freeze({SOFT:"SOFT",HARD:"HARD"});const c=Object.freeze({ROUND_ROBIN:"ROUND_ROBIN",LESS_RECENTLY_USED:"LESS_RECENTLY_USED"});class k{constructor(e){this.pool=e,this.nextWorkerIndex=0}choose(){const e=this.pool.workers[this.nextWorkerIndex];return this.nextWorkerIndex=this.pool.workers.length-1===this.nextWorkerIndex?0:this.nextWorkerIndex+1,e}}class l{constructor(e){this.pool=e}choose(){const e=this.pool.type===i.DYNAMIC;let t,r=1/0;for(const[s,o]of this.pool.tasks){if(!e&&0===o)return s;o<r&&(t=s,r=o)}return t}}class u{constructor(e,t,r=c.ROUND_ROBIN){this.pool=e,this.createDynamicallyWorkerCallback=t,this.workerChoiceStrategy=d.getWorkerChoiceStrategy(this.pool,r)}choose(){const e=this.pool.findFreeTasksMapEntry();return e?e[0]:this.pool.busy?this.workerChoiceStrategy.choose():this.createDynamicallyWorkerCallback()}}class p{constructor(e,t,r=c.ROUND_ROBIN){this.pool=e,this.createDynamicallyWorkerCallback=t,this.setWorkerChoiceStrategy(r)}getPoolWorkerChoiceStrategy(e=c.ROUND_ROBIN){return this.pool.type===i.DYNAMIC?new u(this.pool,this.createDynamicallyWorkerCallback,e):d.getWorkerChoiceStrategy(this.pool,e)}setWorkerChoiceStrategy(e){this.workerChoiceStrategy=this.getPoolWorkerChoiceStrategy(e)}execute(){return this.workerChoiceStrategy.choose()}}class d{static getWorkerChoiceStrategy(e,t=c.ROUND_ROBIN){switch(t){case c.ROUND_ROBIN:return new k(e);case c.LESS_RECENTLY_USED:return new l(e);default:throw new Error(`Worker choice strategy '${t}' not found`)}}}const w=()=>{};class W{constructor(e,t,r){if(this.numberOfWorkers=e,this.filePath=t,this.opts=r,this.workers=[],this.tasks=new Map,this.promiseMap=new Map,this.nextMessageId=0,!this.isMain())throw new Error("Cannot start a pool from a worker!");this.checkNumberOfWorkers(this.numberOfWorkers),this.checkFilePath(this.filePath),this.checkPoolOptions(this.opts),this.setupHook();for(let e=1;e<=this.numberOfWorkers;e++)this.createAndSetupWorker();this.opts.enableEvents&&(this.emitter=new a),this.workerChoiceStrategyContext=new p(this,(()=>{const e=this.createAndSetupWorker();return this.registerWorkerMessageListener(e,(t=>{const r=this.tasks.get(e);var s;s=h.HARD,(t.kill===s||0===r)&&this.destroyWorker(e)})),e}),this.opts.workerChoiceStrategy)}checkFilePath(e){if(!e)throw new Error("Please specify a file with a worker implementation")}checkNumberOfWorkers(e){if(null==e)throw new Error("Cannot instantiate a pool without specifying the number of workers");if(!Number.isSafeInteger(e))throw new Error("Cannot instantiate a pool with a non integer number of workers");if(e<0)throw new Error("Cannot instantiate a pool with a negative number of workers");if(this.type===i.FIXED&&0===e)throw new Error("Cannot instantiate a fixed pool with no worker")}checkPoolOptions(e){var t,r;this.opts.workerChoiceStrategy=null!==(t=e.workerChoiceStrategy)&&void 0!==t?t:c.ROUND_ROBIN,this.opts.enableEvents=null===(r=e.enableEvents)||void 0===r||r}get numberOfRunningTasks(){return this.promiseMap.size}setWorkerChoiceStrategy(e){this.opts.workerChoiceStrategy=e,this.workerChoiceStrategyContext.setWorkerChoiceStrategy(e)}internalGetBusyStatus(){return this.numberOfRunningTasks>=this.numberOfWorkers&&!1===this.findFreeTasksMapEntry()}findFreeTasksMapEntry(){for(const[e,t]of this.tasks)if(0===t)return[e,t];return!1}execute(e){const t=this.chooseWorker();this.increaseWorkersTask(t),this.checkAndEmitBusy();const r=++this.nextMessageId,s=this.internalExecute(t,r);return this.sendToWorker(t,{data:e||{},id:r}),s}async destroy(){await Promise.all(this.workers.map((e=>this.destroyWorker(e))))}setupHook(){}increaseWorkersTask(e){this.stepWorkerNumberOfTasks(e,1)}decreaseWorkersTasks(e){this.stepWorkerNumberOfTasks(e,-1)}stepWorkerNumberOfTasks(e,t){const r=this.tasks.get(e);if(void 0===r)throw Error("Worker could not be found in tasks map");this.tasks.set(e,r+t)}removeWorker(e){const t=this.workers.indexOf(e);this.workers.splice(t,1),this.tasks.delete(e)}chooseWorker(){return this.workerChoiceStrategyContext.execute()}internalExecute(e,t){return new Promise(((r,s)=>{this.promiseMap.set(t,{resolve:r,reject:s,worker:e})}))}createAndSetupWorker(){var e,t,r;const s=this.createWorker();return s.on("error",null!==(e=this.opts.errorHandler)&&void 0!==e?e:w),s.on("online",null!==(t=this.opts.onlineHandler)&&void 0!==t?t:w),s.on("exit",null!==(r=this.opts.exitHandler)&&void 0!==r?r:w),s.once("exit",(()=>this.removeWorker(s))),this.workers.push(s),this.tasks.set(s,0),this.afterWorkerSetup(s),s}workerListener(){return e=>{if(e.id){const t=this.promiseMap.get(e.id);t&&(this.decreaseWorkersTasks(t.worker),e.error?t.reject(e.error):t.resolve(e.data),this.promiseMap.delete(e.id))}}}checkAndEmitBusy(){var e;this.opts.enableEvents&&this.busy&&(null===(e=this.emitter)||void 0===e||e.emit("busy"))}}class y extends W{constructor(e,t,r={}){super(e,t,r),this.opts=r}setupHook(){t.setupMaster({exec:this.filePath})}isMain(){return t.isMaster}destroyWorker(e){this.sendToWorker(e,{kill:1}),e.kill()}sendToWorker(e,t){e.send(t)}registerWorkerMessageListener(e,t){e.on("message",t)}createWorker(){return t.fork(this.opts.env)}afterWorkerSetup(e){this.registerWorkerMessageListener(e,super.workerListener())}get type(){return i.FIXED}get busy(){return this.internalGetBusyStatus()}}class g extends W{constructor(e,t,r={}){super(e,t,r)}isMain(){return r.isMainThread}async destroyWorker(e){this.sendToWorker(e,{kill:1}),await e.terminate()}sendToWorker(e,t){e.postMessage(t)}registerWorkerMessageListener(e,t){var r;null===(r=e.port2)||void 0===r||r.on("message",t)}createWorker(){return new r.Worker(this.filePath,{env:r.SHARE_ENV})}afterWorkerSetup(e){const{port1:t,port2:s}=new r.MessageChannel;e.postMessage({parent:t},[t]),e.port1=t,e.port2=s,this.registerWorkerMessageListener(e,super.workerListener())}get type(){return i.FIXED}get busy(){return this.internalGetBusyStatus()}}const m=h.SOFT;class f extends s.AsyncResource{constructor(e,t,r,s,o={killBehavior:m,maxInactiveTime:6e4}){var i,n,a;super(e),this.mainWorker=s,this.opts=o,this.killBehavior=null!==(i=this.opts.killBehavior)&&void 0!==i?i:m,this.maxInactiveTime=null!==(n=this.opts.maxInactiveTime)&&void 0!==n?n:6e4,this.async=!!this.opts.async,this.lastTask=Date.now(),this.checkFunctionInput(r),t||(this.interval=setInterval(this.checkAlive.bind(this),this.maxInactiveTime/2),this.checkAlive.bind(this)()),null===(a=this.mainWorker)||void 0===a||a.on("message",(e=>{(null==e?void 0:e.data)&&e.id?this.async?this.runInAsyncScope(this.runAsync.bind(this),this,r,e):this.runInAsyncScope(this.run.bind(this),this,r,e):e.parent?this.mainWorker=e.parent:e.kill&&(this.interval&&clearInterval(this.interval),this.emitDestroy())}))}checkFunctionInput(e){if(!e)throw new Error("fn parameter is mandatory")}getMainWorker(){if(!this.mainWorker)throw new Error("Main worker was not set");return this.mainWorker}checkAlive(){Date.now()-this.lastTask>this.maxInactiveTime&&this.sendToMainWorker({kill:this.killBehavior})}handleError(e){return e}run(e,t){try{const r=e(t.data);this.sendToMainWorker({data:r,id:t.id}),this.lastTask=Date.now()}catch(e){const r=this.handleError(e);this.sendToMainWorker({error:r,id:t.id}),this.lastTask=Date.now()}}runAsync(e,t){e(t.data).then((e=>(this.sendToMainWorker({data:e,id:t.id}),this.lastTask=Date.now(),null))).catch((e=>{const r=this.handleError(e);this.sendToMainWorker({error:r,id:t.id}),this.lastTask=Date.now()}))}}exports.AbstractWorker=f,exports.ClusterWorker=class extends f{constructor(e,r={}){super("worker-cluster-pool:pioardi",t.isMaster,e,t.worker,r)}sendToMainWorker(e){this.getMainWorker().send(e)}handleError(e){return e instanceof Error?e.message:e}},exports.DynamicClusterPool=class extends y{constructor(e,t,r,s={}){super(e,r,s),this.max=t}get type(){return i.DYNAMIC}get busy(){return this.workers.length===this.max}},exports.DynamicThreadPool=class extends g{constructor(e,t,r,s={}){super(e,r,s),this.max=t}get type(){return i.DYNAMIC}get busy(){return this.workers.length===this.max}},exports.FixedClusterPool=y,exports.FixedThreadPool=g,exports.KillBehaviors=h,exports.ThreadWorker=class extends f{constructor(e,t={}){super("worker-thread-pool:pioardi",r.isMainThread,e,r.parentPort,t)}sendToMainWorker(e){this.getMainWorker().postMessage(e)}},exports.WorkerChoiceStrategies=c;
import type { MessageValue, PromiseWorkerResponseWrapper } from '../utility-types';
import type { IPoolInternal } from './pool-internal';
import { PoolEmitter } from './pool-internal';
import { PoolEmitter, PoolType } from './pool-internal';
import type { WorkerChoiceStrategy } from './selection-strategies';

@@ -71,2 +71,8 @@ import { WorkerChoiceStrategyContext } from './selection-strategies';

workerChoiceStrategy?: WorkerChoiceStrategy;
/**
* Pool events emission.
*
* Default to true.
*/
enableEvents?: boolean;
}

@@ -89,3 +95,5 @@ /**

/** @inheritdoc */
readonly emitter: PoolEmitter;
readonly emitter?: PoolEmitter;
/** @inheritdoc */
readonly max?: number;
/**

@@ -120,7 +128,15 @@ * The promise map.

private checkNumberOfWorkers;
private checkPoolOptions;
/** @inheritdoc */
get dynamic(): boolean;
abstract get type(): PoolType;
/** @inheritdoc */
get numberOfRunningTasks(): number;
/** @inheritdoc */
setWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy): void;
/** @inheritdoc */
abstract get busy(): boolean;
protected internalGetBusyStatus(): boolean;
/** @inheritdoc */
findFreeTasksMapEntry(): [Worker, number] | false;
/** @inheritdoc */
execute(data: Data): Promise<Response>;

@@ -145,3 +161,3 @@ /** @inheritdoc */

/**
* Increase the number of tasks that the given workers has done.
* Increase the number of tasks that the given workers has applied.
*

@@ -152,3 +168,3 @@ * @param worker Worker whose tasks are increased.

/**
* Decrease the number of tasks that the given workers has done.
* Decrease the number of tasks that the given workers has applied.
*

@@ -159,3 +175,3 @@ * @param worker Worker whose tasks are decreased.

/**
* Step the number of tasks that the given workers has done.
* Step the number of tasks that the given workers has applied.
*

@@ -219,2 +235,3 @@ * @param worker Worker whose tasks are set.

protected workerListener(): (message: MessageValue<Response>) => void;
private checkAndEmitBusy;
}

@@ -0,1 +1,2 @@

import { PoolType } from '../pool-internal';
import type { ClusterPoolOptions } from './fixed';

@@ -27,3 +28,5 @@ import { FixedClusterPool } from './fixed';

/** @inheritdoc */
get dynamic(): boolean;
get type(): PoolType;
/** @inheritdoc */
get busy(): boolean;
}

@@ -6,2 +6,3 @@ /// <reference types="node" />

import { AbstractPool } from '../abstract-pool';
import { PoolType } from '../pool-internal';
/**

@@ -50,2 +51,6 @@ * Options for a poolifier cluster pool.

protected afterWorkerSetup(worker: Worker): void;
/** @inheritdoc */
get type(): PoolType;
/** @inheritdoc */
get busy(): boolean;
}

@@ -6,2 +6,9 @@ /// <reference types="node" />

/**
* Pool types.
*/
export declare enum PoolType {
FIXED = "fixed",
DYNAMIC = "dynamic"
}
/**
* Internal poolifier pool emitter.

@@ -37,9 +44,9 @@ */

*/
readonly emitter: PoolEmitter;
readonly emitter?: PoolEmitter;
/**
* Whether the pool is dynamic or not.
* Pool type.
*
* If it is dynamic, it provides the `max` property.
* If it is `'dynamic'`, it provides the `max` property.
*/
readonly dynamic: boolean;
readonly type: PoolType;
/**

@@ -49,2 +56,22 @@ * Maximum number of workers that can be created by this pool.

readonly max?: number;
/**
* Whether the pool is busy or not.
*
* The pool busyness boolean status.
*/
readonly busy: boolean;
/**
* Number of tasks currently concurrently running.
*/
readonly numberOfRunningTasks: number;
/**
* Find a tasks map entry with a free worker based on the number of tasks the worker has applied.
*
* If an entry is found with a worker that has `0` tasks, it is detected as free.
*
* If no tasks map entry with a free worker was found, `false` will be returned.
*
* @returns A tasks map entry with a free worker if there was one, otherwise `false`.
*/
findFreeTasksMapEntry(): [Worker, number] | false;
}
import type { PoolOptions } from '../abstract-pool';
import { PoolType } from '../pool-internal';
import type { ThreadWorkerWithMessageChannel } from './fixed';

@@ -28,3 +29,5 @@ import { FixedThreadPool } from './fixed';

/** @inheritdoc */
get dynamic(): boolean;
get type(): PoolType;
/** @inheritdoc */
get busy(): boolean;
}

@@ -6,2 +6,3 @@ /// <reference types="node" />

import { AbstractPool } from '../abstract-pool';
import { PoolType } from '../pool-internal';
/**

@@ -41,2 +42,6 @@ * A thread worker with message channels for communication between main thread and thread worker.

protected afterWorkerSetup(worker: ThreadWorkerWithMessageChannel): void;
/** @inheritdoc */
get type(): PoolType;
/** @inheritdoc */
get busy(): boolean;
}
{
"name": "poolifier",
"version": "2.0.0",
"version": "2.0.1",
"description": "A fast, easy to use Node.js Worker Thread Pool and Cluster Pool implementation",

@@ -8,2 +8,3 @@ "main": "lib/index.js",

"build": "rollup --config --environment BUILD:development",
"build:typedoc": "rollup --config --environment BUILD:development --environment DOCUMENTATION",
"build:prod": "rollup --config",

@@ -66,10 +67,10 @@ "benchmark": "npm run build && node -r source-map-support/register benchmarks/internal/bench.js",

"devDependencies": {
"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@types/node": "^14.14.35",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"benchmark": "^2.1.4",
"eslint": "^7.21.0",
"eslint": "^7.22.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^32.2.0",
"eslint-plugin-jsdoc": "^32.3.0",
"eslint-plugin-node": "^11.1.0",

@@ -81,3 +82,3 @@ "eslint-plugin-prettierx": "^0.17.1",

"microtime": "^3.0.0",
"mocha": "^8.3.0",
"mocha": "^8.3.2",
"mocha-lcov-reporter": "^1.3.0",

@@ -88,3 +89,3 @@ "nyc": "^15.1.0",

"prettierx": "^0.17.0",
"rollup": "^2.40.0",
"rollup": "^2.41.3",
"rollup-plugin-analyzer": "^4.0.0",

@@ -97,4 +98,4 @@ "rollup-plugin-command": "^1.1.3",

"source-map-support": "^0.5.19",
"typedoc": "^0.20.28",
"typescript": "^4.2.2"
"typedoc": "^0.20.32",
"typescript": "^4.2.3"
},

@@ -101,0 +102,0 @@ "engines": {

@@ -32,3 +32,3 @@ <div align="center">

## Why Poolifier?
## Why Poolifier?

@@ -209,3 +209,3 @@ Poolifier is used to perform CPU intensive and I/O intensive tasks on nodejs servers, it implements worker pools (yes, more worker pool implementations, so you can choose which one fit better for you) using [worker-threads](https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads) and cluster pools using [Node.js cluster](https://nodejs.org/api/cluster.html) modules.

Now **if your task runs on libuv thread pool**, you can try to:
**If your task runs on libuv thread pool**, you can try to:

@@ -212,0 +212,0 @@ - Tune the libuv thread pool size setting the [UV_THREADPOOL_SIZE](https://nodejs.org/api/cli.html#cli_uv_threadpool_size_size)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc