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

piscina

Package Overview
Dependencies
Maintainers
6
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piscina - npm Package Compare versions

Comparing version 3.2.0 to 4.0.0

test/messages.ts

2

dist/package.json
{
"name": "piscina",
"version": "3.2.0",
"version": "4.0.0",
"description": "A fast, efficient Node.js Worker Thread Pool implementation",

@@ -5,0 +5,0 @@ "main": "./dist/src/index.js",

/// <reference types="node" />
import type { MessagePort } from 'worker_threads';
export declare const READY = "_WORKER_READY";
export interface StartupMessage {

@@ -18,3 +19,3 @@ filename: string | null;

export interface ReadyMessage {
ready: true;
[READY]: true;
}

@@ -21,0 +22,0 @@ export interface ResponseMessage {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.kFieldCount = exports.kResponseCountField = exports.kRequestCountField = exports.isTaskQueue = exports.markMovable = exports.isMovable = exports.isTransferable = exports.kQueueOptions = exports.kValue = exports.kTransferable = exports.commonState = void 0;
exports.kFieldCount = exports.kResponseCountField = exports.kRequestCountField = exports.isTaskQueue = exports.markMovable = exports.isMovable = exports.isTransferable = exports.kQueueOptions = exports.kValue = exports.kTransferable = exports.commonState = exports.READY = void 0;
exports.READY = '_WORKER_READY';
;

@@ -5,0 +6,0 @@ exports.commonState = {

@@ -79,2 +79,4 @@ /// <reference types="node" />

destroy(): Promise<void>;
get maxThreads(): number;
get minThreads(): number;
get options(): FilledOptions;

@@ -81,0 +83,0 @@ get threads(): Worker[];

@@ -435,13 +435,15 @@ "use strict";

}
function onReady() {
if (workerInfo.currentUsage() === 0) {
workerInfo.unref();
}
if (!workerInfo.isReady()) {
workerInfo.markAsReady();
}
}
function onEventMessage(message) {
pool.publicInterface.emit('message', message);
}
worker.on('message', (message) => {
if (message.ready === true) {
if (workerInfo.currentUsage() === 0) {
workerInfo.unref();
}
if (!workerInfo.isReady()) {
workerInfo.markAsReady();
}
return;
}
worker.emit('error', new Error(`Unexpected message on Worker: ${util_1.inspect(message)}`));
message instanceof Object && common_1.READY in message ? onReady() : onEventMessage(message);
});

@@ -775,2 +777,8 @@ worker.on('error', (err) => {

}
get maxThreads() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").options.maxThreads;
}
get minThreads() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").options.minThreads;
}
get options() {

@@ -777,0 +785,0 @@ return __classPrivateFieldGet(this, _Piscina_pool, "f").options;

@@ -94,3 +94,3 @@ "use strict";

}
const readyMessage = { ready: true };
const readyMessage = { [common_1.READY]: true };
worker_threads_1.parentPort.postMessage(readyMessage);

@@ -97,0 +97,0 @@ port.on('message', onMessage.bind(null, port, sharedBuffer));

{
"name": "piscina",
"version": "3.2.0",
"version": "4.0.0",
"description": "A fast, efficient Node.js Worker Thread Pool implementation",

@@ -5,0 +5,0 @@ "main": "./dist/src/index.js",

@@ -20,3 +20,3 @@ ![Piscina Logo](https://avatars1.githubusercontent.com/u/65627548?s=200&v=4)

For Node.js 12.x and higher.
For Node.js 16.x and higher.

@@ -259,3 +259,3 @@ [MIT Licensed][].

Additional examples can be found in the GitHub repo at
https://github.com/jasnell/piscina/tree/master/examples
https://github.com/piscinajs/piscina/tree/master/examples

@@ -423,2 +423,6 @@ ## Class: `Piscina`

### Event: `'message'`
A `'message'` event is emitted whenever a message is received from a worker thread.
### Property: `completed` (readonly)

@@ -789,2 +793,7 @@

### 4.0.0
* Drop Node.js 14.x support
* Add Node.js 20.x to CI
### 3.2.0

@@ -791,0 +800,0 @@

import type { MessagePort } from 'worker_threads';
export const READY = '_WORKER_READY';
export interface StartupMessage {

@@ -20,3 +22,3 @@ filename : string | null;

export interface ReadyMessage {
ready: true
[READY]: true
};

@@ -29,3 +31,2 @@

}
export const commonState = {

@@ -32,0 +33,0 @@ isWorkerThread: false,

@@ -14,3 +14,3 @@ import { Worker, MessageChannel, MessagePort, receiveMessageOnPort } from 'worker_threads';

import {
ReadyMessage,
READY,
RequestMessage,

@@ -620,16 +620,18 @@ ResponseMessage,

worker.on('message', (message : ReadyMessage) => {
if (message.ready === true) {
if (workerInfo.currentUsage() === 0) {
workerInfo.unref();
}
function onReady () {
if (workerInfo.currentUsage() === 0) {
workerInfo.unref();
}
if (!workerInfo.isReady()) {
workerInfo.markAsReady();
}
return;
if (!workerInfo.isReady()) {
workerInfo.markAsReady();
}
}
worker.emit('error', new Error(
`Unexpected message on Worker: ${inspect(message)}`));
function onEventMessage (message: any) {
pool.publicInterface.emit('message', message);
}
worker.on('message', (message : any) => {
message instanceof Object && READY in message ? onReady() : onEventMessage(message);
});

@@ -1035,2 +1037,10 @@

get maxThreads (): number {
return this.#pool.options.maxThreads;
}
get minThreads (): number {
return this.#pool.options.minThreads;
}
get options () : FilledOptions {

@@ -1037,0 +1047,0 @@ return this.#pool.options;

import { parentPort, MessagePort, receiveMessageOnPort, workerData } from 'worker_threads';
import { pathToFileURL } from 'url';
import {
READY,
commonState,

@@ -92,3 +93,3 @@ ReadyMessage,

const readyMessage : ReadyMessage = { ready: true };
const readyMessage : ReadyMessage = { [READY]: true };
parentPort!.postMessage(readyMessage);

@@ -95,0 +96,0 @@

import { MessageChannel } from 'worker_threads';
import { cpus } from 'os';
import Piscina from '..';

@@ -134,1 +135,45 @@ import { test } from 'tap';

});
test('Piscina.maxThreads should return the max number of threads to be used (default)', ({ equal, plan }) => {
plan(1);
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js')
});
const maxThreads = (cpus().length || 1) * 1.5;
equal(pool.maxThreads, maxThreads);
});
test('Piscina.minThreads should return the max number of threads to be used (custom)', ({ equal, plan }) => {
const maxThreads = 3;
const pool = new Piscina({
maxThreads,
filename: resolve(__dirname, 'fixtures/eval.js')
});
plan(1);
equal(pool.maxThreads, maxThreads);
});
test('Piscina.minThreads should return the max number of threads to be used (default)', ({ equal, plan }) => {
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js')
});
const minThreads = Math.max((cpus().length || 1) / 2, 1);
plan(1);
equal(pool.minThreads, minThreads);
});
test('Piscina.minThreads should return the max number of threads to be used (custom)', ({ equal, plan }) => {
const minThreads = 2;
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js'),
minThreads
});
plan(1);
equal(pool.minThreads, minThreads);
});

@@ -126,4 +126,6 @@ import Piscina from '..';

filename: resolve(__dirname, 'fixtures/simple-workerdata.ts'),
workerData: process.env
}) as any), /Cannot transfer object of unsupported type./);
workerData: {
hello () {}
}
}) as any), /could not be cloned./);
});

@@ -130,0 +132,0 @@

@@ -47,12 +47,1 @@ import Piscina from '..';

});
test('using parentPort is treated as an error', async ({ rejects }) => {
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js')
});
await rejects(
pool.runTask(`
require('worker_threads').parentPort.postMessage("some message");
new Promise(() => {}) /* act as if we were doing some work */
`), /Unexpected message on Worker: 'some message'/);
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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