Initial commit: notification-elements-demo app

Interactive Angular 19 demo for @sda/notification-elements-ui with
6 sections: Bell & Feed, Notification Center, Inbox, Comments &
Threads, Mention Input, and Full-Featured layout. Includes mock
data, dark mode toggle, and real-time event log.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Giuliano Silvestro
2026-02-13 21:49:19 +10:00
commit 5d0c9ec7eb
36473 changed files with 3778146 additions and 0 deletions

20
node_modules/piscina/dist/abort.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
interface AbortSignalEventTargetAddOptions {
once: boolean;
}
export interface AbortSignalEventTarget {
addEventListener: (name: 'abort', listener: () => void, options?: AbortSignalEventTargetAddOptions) => void;
removeEventListener: (name: 'abort', listener: () => void) => void;
aborted?: boolean;
reason?: unknown;
}
export interface AbortSignalEventEmitter {
off: (name: 'abort', listener: () => void) => void;
once: (name: 'abort', listener: () => void) => void;
}
export type AbortSignalAny = AbortSignalEventTarget | AbortSignalEventEmitter;
export declare class AbortError extends Error {
constructor(reason?: AbortSignalEventTarget['reason']);
get name(): string;
}
export declare function onabort(abortSignal: AbortSignalAny, listener: () => void): void;
export {};

24
node_modules/piscina/dist/abort.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbortError = void 0;
exports.onabort = onabort;
class AbortError extends Error {
constructor(reason) {
// TS does not recognizes the cause clause
// @ts-expect-error
super('The task has been aborted', { cause: reason });
}
get name() {
return 'AbortError';
}
}
exports.AbortError = AbortError;
function onabort(abortSignal, listener) {
if ('addEventListener' in abortSignal) {
abortSignal.addEventListener('abort', listener, { once: true });
}
else {
abortSignal.once('abort', listener);
}
}
//# sourceMappingURL=abort.js.map

1
node_modules/piscina/dist/abort.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"abort.js","sourceRoot":"","sources":["../src/abort.ts"],"names":[],"mappings":";;;AAkCA,0BAMC;AAlBD,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAa,MAAyC;QACpD,0CAA0C;QAC1C,mBAAmB;QACnB,KAAK,CAAC,2BAA2B,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,IAAI;QACN,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAVD,gCAUC;AAED,SAAgB,OAAO,CAAE,WAA2B,EAAE,QAAoB;IACxE,IAAI,kBAAkB,IAAI,WAAW,EAAE,CAAC;QACtC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,CAAC;SAAM,CAAC;QACN,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}

30
node_modules/piscina/dist/common.d.ts generated vendored Normal file
View File

@@ -0,0 +1,30 @@
import type { Histogram } from 'node:perf_hooks';
import type { HistogramSummary } from './types';
export declare const READY = "_WORKER_READY";
/**
* True if the object implements the Transferable interface
*
* @export
* @param {unknown} value
* @return {*} {boolean}
*/
export declare function isTransferable(value: unknown): boolean;
/**
* True if object implements Transferable and has been returned
* by the Piscina.move() function
*
* TODO: narrow down the type of value
* @export
* @param {(unknown & PiscinaMovable)} value
* @return {*} {boolean}
*/
export declare function isMovable(value: any): boolean;
export declare function markMovable(value: {}): void;
export declare const commonState: {
isWorkerThread: boolean;
workerData: undefined;
};
export declare function createHistogramSummary(histogram: Histogram): HistogramSummary;
export declare function toHistogramIntegerNano(milliseconds: number): number;
export declare function maybeFileURLToPath(filename: string): string;
export declare function getAvailableParallelism(): number;

99
node_modules/piscina/dist/common.js generated vendored Normal file
View File

@@ -0,0 +1,99 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.commonState = exports.READY = void 0;
exports.isTransferable = isTransferable;
exports.isMovable = isMovable;
exports.markMovable = markMovable;
exports.createHistogramSummary = createHistogramSummary;
exports.toHistogramIntegerNano = toHistogramIntegerNano;
exports.maybeFileURLToPath = maybeFileURLToPath;
exports.getAvailableParallelism = getAvailableParallelism;
const node_url_1 = require("node:url");
const node_os_1 = require("node:os");
const symbols_1 = require("./symbols");
// States wether the worker is ready to receive tasks
exports.READY = '_WORKER_READY';
/**
* True if the object implements the Transferable interface
*
* @export
* @param {unknown} value
* @return {*} {boolean}
*/
function isTransferable(value) {
return (value != null &&
typeof value === 'object' &&
symbols_1.kTransferable in value &&
symbols_1.kValue in value);
}
/**
* True if object implements Transferable and has been returned
* by the Piscina.move() function
*
* TODO: narrow down the type of value
* @export
* @param {(unknown & PiscinaMovable)} value
* @return {*} {boolean}
*/
function isMovable(value) {
return isTransferable(value) && value[symbols_1.kMovable] === true;
}
function markMovable(value) {
Object.defineProperty(value, symbols_1.kMovable, {
enumerable: false,
configurable: true,
writable: true,
value: true
});
}
// State of Piscina pool
exports.commonState = {
isWorkerThread: false,
workerData: undefined
};
function createHistogramSummary(histogram) {
const { mean, stddev, min, max } = histogram;
return {
average: mean / 1000,
mean: mean / 1000,
stddev,
min: min / 1000,
max: max / 1000,
p0_001: histogram.percentile(0.001) / 1000,
p0_01: histogram.percentile(0.01) / 1000,
p0_1: histogram.percentile(0.1) / 1000,
p1: histogram.percentile(1) / 1000,
p2_5: histogram.percentile(2.5) / 1000,
p10: histogram.percentile(10) / 1000,
p25: histogram.percentile(25) / 1000,
p50: histogram.percentile(50) / 1000,
p75: histogram.percentile(75) / 1000,
p90: histogram.percentile(90) / 1000,
p97_5: histogram.percentile(97.5) / 1000,
p99: histogram.percentile(99) / 1000,
p99_9: histogram.percentile(99.9) / 1000,
p99_99: histogram.percentile(99.99) / 1000,
p99_999: histogram.percentile(99.999) / 1000
};
}
function toHistogramIntegerNano(milliseconds) {
return Math.max(1, Math.trunc(milliseconds * 1000));
}
function maybeFileURLToPath(filename) {
return filename.startsWith('file:')
? (0, node_url_1.fileURLToPath)(new node_url_1.URL(filename))
: filename;
}
// TODO: drop on v5
function getAvailableParallelism() {
if (typeof node_os_1.availableParallelism === 'function') {
return (0, node_os_1.availableParallelism)();
}
try {
return (0, node_os_1.cpus)().length;
}
catch {
return 1;
}
}
//# sourceMappingURL=common.js.map

1
node_modules/piscina/dist/common.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;;AAiBA,wCAOC;AAWD,8BAEC;AAED,kCAOC;AAQD,wDAyBC;AAED,wDAEC;AAED,gDAIC;AAGD,0DAUC;AArGD,uCAA8C;AAC9C,qCAAqD;AAGrD,uCAA4D;AAE5D,qDAAqD;AACxC,QAAA,KAAK,GAAG,eAAe,CAAC;AAErC;;;;;;GAMG;AACH,SAAgB,cAAc,CAAE,KAAc;IAC5C,OAAO,CACL,KAAK,IAAI,IAAI;QACb,OAAO,KAAK,KAAK,QAAQ;QACzB,uBAAa,IAAI,KAAK;QACtB,gBAAM,IAAI,KAAK,CAChB,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAE,KAAU;IACnC,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,kBAAQ,CAAC,KAAK,IAAI,CAAC;AAC3D,CAAC;AAED,SAAgB,WAAW,CAAE,KAAS;IACpC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,kBAAQ,EAAE;QACrC,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;AACL,CAAC;AAED,wBAAwB;AACX,QAAA,WAAW,GAAG;IACzB,cAAc,EAAE,KAAK;IACrB,UAAU,EAAE,SAAS;CACtB,CAAC;AAEF,SAAgB,sBAAsB,CAAE,SAAoB;IAC1D,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAE7C,OAAO;QACL,OAAO,EAAE,IAAI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,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,SAAgB,kBAAkB,CAAE,QAAiB;IACnD,OAAO,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;QACjC,CAAC,CAAC,IAAA,wBAAa,EAAC,IAAI,cAAG,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC,CAAC,QAAQ,CAAC;AACf,CAAC;AAED,mBAAmB;AACnB,SAAgB,uBAAuB;IACrC,IAAI,OAAO,8BAAoB,KAAK,UAAU,EAAE,CAAC;QAC/C,OAAO,IAAA,8BAAoB,GAAE,CAAC;IAChC,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAA,cAAI,GAAE,CAAC,MAAM,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}

7
node_modules/piscina/dist/errors.d.ts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
export declare const Errors: {
ThreadTermination: () => Error;
FilenameNotProvided: () => Error;
TaskQueueAtLimit: () => Error;
NoTaskQueueAvailable: () => Error;
CloseTimeout: () => Error;
};

11
node_modules/piscina/dist/errors.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Errors = void 0;
exports.Errors = {
ThreadTermination: () => new Error('Terminating worker thread'),
FilenameNotProvided: () => new Error('filename must be provided to run() or in options object'),
TaskQueueAtLimit: () => new Error('Task queue is at limit'),
NoTaskQueueAvailable: () => new Error('No task queue available and all Workers are busy'),
CloseTimeout: () => new Error('Close operation timed out')
};
//# sourceMappingURL=errors.js.map

1
node_modules/piscina/dist/errors.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG;IACpB,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,2BAA2B,CAAC;IAC/D,mBAAmB,EAAE,GAAG,EAAE,CACxB,IAAI,KAAK,CAAC,yDAAyD,CAAC;IACtE,gBAAgB,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,wBAAwB,CAAC;IAC3D,oBAAoB,EAAE,GAAG,EAAE,CACzB,IAAI,KAAK,CAAC,kDAAkD,CAAC;IAC/D,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,2BAA2B,CAAC;CAC3D,CAAC"}

13
node_modules/piscina/dist/esm-wrapper.mjs generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import mod from "./main.js";
export default mod;
export const ArrayTaskQueue = mod.ArrayTaskQueue;
export const FixedQueue = mod.FixedQueue;
export const Piscina = mod.Piscina;
export const isWorkerThread = mod.isWorkerThread;
export const move = mod.move;
export const queueOptionsSymbol = mod.queueOptionsSymbol;
export const transferableSymbol = mod.transferableSymbol;
export const valueSymbol = mod.valueSymbol;
export const version = mod.version;
export const workerData = mod.workerData;

90
node_modules/piscina/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,90 @@
import { Worker, MessagePort } from 'node:worker_threads';
import { EventEmitterAsyncResource } from 'node:events';
import { version } from '../package.json';
import type { Transferable, ResourceLimits, EnvSpecifier } from './types';
import { kQueueOptions, kTransferable, kValue } from './symbols';
import { TaskQueue, ArrayTaskQueue, FixedQueue, PiscinaTask, TransferList, TransferListItem } from './task_queue';
import { AbortSignalAny } from './abort';
interface Options {
filename?: string | null;
name?: string;
minThreads?: number;
maxThreads?: number;
idleTimeout?: number;
maxQueue?: number | 'auto';
concurrentTasksPerWorker?: number;
useAtomics?: boolean;
resourceLimits?: ResourceLimits;
argv?: string[];
execArgv?: string[];
env?: EnvSpecifier;
workerData?: any;
taskQueue?: TaskQueue;
niceIncrement?: number;
trackUnmanagedFds?: boolean;
closeTimeout?: number;
recordTiming?: boolean;
}
interface FilledOptions extends Options {
filename: string | null;
name: string;
minThreads: number;
maxThreads: number;
idleTimeout: number;
maxQueue: number;
concurrentTasksPerWorker: number;
useAtomics: boolean;
taskQueue: TaskQueue;
niceIncrement: number;
closeTimeout: number;
recordTiming: boolean;
}
interface RunOptions {
transferList?: TransferList;
filename?: string | null;
signal?: AbortSignalAny | null;
name?: string | null;
}
interface CloseOptions {
force?: boolean;
}
export default class Piscina<T = any, R = any> extends EventEmitterAsyncResource {
#private;
constructor(options?: Options);
/** @deprecated Use run(task, options) instead **/
runTask(task: T, transferList?: TransferList, filename?: string, abortSignal?: AbortSignalAny): Promise<R>;
/** @deprecated Use run(task, options) instead **/
runTask(task: T, transferList?: TransferList, filename?: AbortSignalAny, abortSignal?: undefined): Promise<R>;
/** @deprecated Use run(task, options) instead **/
runTask(task: T, transferList?: string, filename?: AbortSignalAny, abortSignal?: undefined): Promise<R>;
/** @deprecated Use run(task, options) instead **/
runTask(task: T, transferList?: AbortSignalAny, filename?: undefined, abortSignal?: undefined): Promise<R>;
run(task: T, options?: RunOptions): Promise<R>;
close(options?: CloseOptions): Promise<void>;
destroy(): Promise<void>;
get maxThreads(): number;
get minThreads(): number;
get options(): FilledOptions;
get threads(): Worker[];
get queueSize(): number;
get completed(): number;
get waitTime(): any;
get runTime(): any;
get utilization(): number;
get duration(): number;
get needsDrain(): boolean;
static get isWorkerThread(): boolean;
static get workerData(): any;
static get version(): string;
static get Piscina(): typeof Piscina;
static get FixedQueue(): typeof FixedQueue;
static get ArrayTaskQueue(): typeof ArrayTaskQueue;
static move(val: Transferable | TransferListItem | ArrayBufferView | ArrayBuffer | MessagePort): ArrayBuffer | ArrayBufferView | MessagePort | Transferable;
static get transferableSymbol(): symbol;
static get valueSymbol(): symbol;
static get queueOptionsSymbol(): symbol;
}
export declare const move: typeof Piscina.move;
export declare const isWorkerThread: boolean;
export declare const workerData: any;
export { Piscina, PiscinaTask, TaskQueue, kTransferable as transferableSymbol, kValue as valueSymbol, kQueueOptions as queueOptionsSymbol, version, FixedQueue };

743
node_modules/piscina/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,743 @@
"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _DirectlyTransferable_value, _ArrayBufferViewTransferable_view, _Piscina_pool;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixedQueue = exports.version = exports.queueOptionsSymbol = exports.valueSymbol = exports.transferableSymbol = exports.Piscina = exports.workerData = exports.isWorkerThread = exports.move = void 0;
const node_worker_threads_1 = require("node:worker_threads");
const node_events_1 = require("node:events");
const node_path_1 = require("node:path");
const node_util_1 = require("node:util");
const node_perf_hooks_1 = require("node:perf_hooks");
const promises_1 = require("node:timers/promises");
const node_assert_1 = __importDefault(require("node:assert"));
const package_json_1 = require("../package.json");
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return package_json_1.version; } });
const symbols_1 = require("./symbols");
Object.defineProperty(exports, "queueOptionsSymbol", { enumerable: true, get: function () { return symbols_1.kQueueOptions; } });
Object.defineProperty(exports, "transferableSymbol", { enumerable: true, get: function () { return symbols_1.kTransferable; } });
Object.defineProperty(exports, "valueSymbol", { enumerable: true, get: function () { return symbols_1.kValue; } });
const task_queue_1 = require("./task_queue");
Object.defineProperty(exports, "FixedQueue", { enumerable: true, get: function () { return task_queue_1.FixedQueue; } });
const worker_pool_1 = require("./worker_pool");
const abort_1 = require("./abort");
const errors_1 = require("./errors");
const common_1 = require("./common");
const cpuParallelism = (0, common_1.getAvailableParallelism)();
const kDefaultOptions = {
filename: null,
name: 'default',
minThreads: Math.max(Math.floor(cpuParallelism / 2), 1),
maxThreads: cpuParallelism * 1.5,
idleTimeout: 0,
maxQueue: Infinity,
concurrentTasksPerWorker: 1,
useAtomics: true,
taskQueue: new task_queue_1.ArrayTaskQueue(),
niceIncrement: 0,
trackUnmanagedFds: true,
closeTimeout: 30000,
recordTiming: true
};
const kDefaultRunOptions = {
transferList: undefined,
filename: null,
signal: null,
name: null
};
const kDefaultCloseOptions = {
force: false
};
class DirectlyTransferable {
constructor(value) {
_DirectlyTransferable_value.set(this, void 0);
__classPrivateFieldSet(this, _DirectlyTransferable_value, value, "f");
}
get [(_DirectlyTransferable_value = new WeakMap(), symbols_1.kTransferable)]() { return __classPrivateFieldGet(this, _DirectlyTransferable_value, "f"); }
get [symbols_1.kValue]() { return __classPrivateFieldGet(this, _DirectlyTransferable_value, "f"); }
}
class ArrayBufferViewTransferable {
constructor(view) {
_ArrayBufferViewTransferable_view.set(this, void 0);
__classPrivateFieldSet(this, _ArrayBufferViewTransferable_view, view, "f");
}
get [(_ArrayBufferViewTransferable_view = new WeakMap(), symbols_1.kTransferable)]() { return __classPrivateFieldGet(this, _ArrayBufferViewTransferable_view, "f").buffer; }
get [symbols_1.kValue]() { return __classPrivateFieldGet(this, _ArrayBufferViewTransferable_view, "f"); }
}
class ThreadPool {
constructor(publicInterface, options) {
var _a;
this.skipQueue = [];
this.completed = 0;
this.start = node_perf_hooks_1.performance.now();
this.inProcessPendingMessages = false;
this.startingUp = false;
this.closingUp = false;
this.workerFailsDuringBootstrap = false;
this.destroying = false;
this.publicInterface = publicInterface;
this.taskQueue = options.taskQueue || new task_queue_1.ArrayTaskQueue();
const filename = options.filename ? (0, common_1.maybeFileURLToPath)(options.filename) : null;
this.options = { ...kDefaultOptions, ...options, filename, maxQueue: 0 };
if (this.options.recordTiming) {
this.runTime = (0, node_perf_hooks_1.createHistogram)();
this.waitTime = (0, node_perf_hooks_1.createHistogram)();
}
// The >= and <= could be > and < but this way we get 100 % coverage 🙃
if (options.maxThreads !== undefined &&
this.options.minThreads >= options.maxThreads) {
this.options.minThreads = options.maxThreads;
}
if (options.minThreads !== undefined &&
this.options.maxThreads <= options.minThreads) {
this.options.maxThreads = options.minThreads;
}
if (options.maxQueue === 'auto') {
this.options.maxQueue = this.options.maxThreads ** 2;
}
else {
this.options.maxQueue = (_a = options.maxQueue) !== null && _a !== void 0 ? _a : kDefaultOptions.maxQueue;
}
this.workers = new worker_pool_1.AsynchronouslyCreatedResourcePool(this.options.concurrentTasksPerWorker);
this.workers.onAvailable((w) => this._onWorkerAvailable(w));
this.startingUp = true;
this._ensureMinimumWorkers();
this.startingUp = false;
this.needsDrain = false;
}
_ensureMinimumWorkers() {
if (this.closingUp || this.destroying) {
return;
}
while (this.workers.size < this.options.minThreads) {
this._addNewWorker();
}
}
_addNewWorker() {
const pool = this;
const worker = new node_worker_threads_1.Worker((0, node_path_1.resolve)(__dirname, 'worker.js'), {
env: this.options.env,
argv: this.options.argv,
execArgv: this.options.execArgv,
resourceLimits: this.options.resourceLimits,
workerData: this.options.workerData,
trackUnmanagedFds: this.options.trackUnmanagedFds
});
const { port1, port2 } = new node_worker_threads_1.MessageChannel();
const workerInfo = new worker_pool_1.WorkerInfo(worker, port1, onMessage);
if (this.startingUp) {
// There is no point in waiting for the initial set of Workers to indicate
// that they are ready, we just mark them as such from the start.
workerInfo.markAsReady();
}
const message = {
filename: this.options.filename,
name: this.options.name,
port: port2,
sharedBuffer: workerInfo.sharedBuffer,
useAtomics: this.options.useAtomics,
niceIncrement: this.options.niceIncrement
};
worker.postMessage(message, [port2]);
function onMessage(message) {
const { taskId, result } = message;
// In case of success: Call the callback that was passed to `runTask`,
// remove the `TaskInfo` associated with the Worker, which marks it as
// free again.
const taskInfo = workerInfo.taskInfos.get(taskId);
workerInfo.taskInfos.delete(taskId);
pool.workers.maybeAvailable(workerInfo);
/* istanbul ignore if */
if (taskInfo === undefined) {
const err = new Error(`Unexpected message from Worker: ${(0, node_util_1.inspect)(message)}`);
pool.publicInterface.emit('error', err);
}
else {
taskInfo.done(message.error, result);
}
pool._processPendingMessages();
}
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) => {
message instanceof Object && common_1.READY in message ? onReady() : onEventMessage(message);
});
worker.on('error', (err) => {
this._onError(worker, workerInfo, err, false);
});
worker.on('exit', (exitCode) => {
if (this.destroying) {
return;
}
const err = new Error(`worker exited with code: ${exitCode}`);
// Only error unfinished tasks on process exit, since there are legitimate
// reasons to exit workers and we want to handle that gracefully when possible.
this._onError(worker, workerInfo, err, true);
});
worker.unref();
port1.on('close', () => {
// The port is only closed if the Worker stops for some reason, but we
// always .unref() the Worker itself. We want to receive e.g. 'error'
// events on it, so we ref it once we know it's going to exit anyway.
worker.ref();
});
this.workers.add(workerInfo);
}
_onError(worker, workerInfo, err, onlyErrorUnfinishedTasks) {
// Work around the bug in https://github.com/nodejs/node/pull/33394
worker.ref = () => { };
const taskInfos = [...workerInfo.taskInfos.values()];
workerInfo.taskInfos.clear();
// Remove the worker from the list and potentially start a new Worker to
// replace the current one.
this._removeWorker(workerInfo);
if (workerInfo.isReady() && !this.workerFailsDuringBootstrap) {
this._ensureMinimumWorkers();
}
else {
// Do not start new workers over and over if they already fail during
// bootstrap, there's no point.
this.workerFailsDuringBootstrap = true;
}
if (taskInfos.length > 0) {
// If there are remaining unfinished tasks, call the callback that was
// passed to `postTask` with the error
for (const taskInfo of taskInfos) {
taskInfo.done(err, null);
}
}
else if (!onlyErrorUnfinishedTasks) {
// If there are no unfinished tasks, instead emit an 'error' event
this.publicInterface.emit('error', err);
}
}
_processPendingMessages() {
if (this.inProcessPendingMessages || !this.options.useAtomics) {
return;
}
this.inProcessPendingMessages = true;
try {
for (const workerInfo of this.workers) {
workerInfo.processPendingMessages();
}
}
finally {
this.inProcessPendingMessages = false;
}
}
_removeWorker(workerInfo) {
workerInfo.destroy();
this.workers.delete(workerInfo);
}
_onWorkerAvailable(workerInfo) {
var _a;
while ((this.taskQueue.size > 0 || this.skipQueue.length > 0) &&
workerInfo.currentUsage() < this.options.concurrentTasksPerWorker) {
// The skipQueue will have tasks that we previously shifted off
// the task queue but had to skip over... we have to make sure
// we drain that before we drain the taskQueue.
const taskInfo = this.skipQueue.shift() ||
this.taskQueue.shift();
// If the task has an abortSignal and the worker has any other
// tasks, we cannot distribute the task to it. Skip for now.
if (taskInfo.abortSignal && workerInfo.taskInfos.size > 0) {
this.skipQueue.push(taskInfo);
break;
}
const now = node_perf_hooks_1.performance.now();
(_a = this.waitTime) === null || _a === void 0 ? void 0 : _a.record((0, common_1.toHistogramIntegerNano)(now - taskInfo.created));
taskInfo.started = now;
workerInfo.postTask(taskInfo);
this._maybeDrain();
return;
}
if (workerInfo.taskInfos.size === 0 &&
this.workers.size > this.options.minThreads) {
workerInfo.idleTimeout = setTimeout(() => {
node_assert_1.default.strictEqual(workerInfo.taskInfos.size, 0);
if (this.workers.size > this.options.minThreads) {
this._removeWorker(workerInfo);
}
}, this.options.idleTimeout).unref();
}
}
runTask(task, options) {
var _a, _b;
let { filename, name } = options;
const { transferList = [] } = options;
if (filename == null) {
filename = this.options.filename;
}
if (name == null) {
name = this.options.name;
}
if (typeof filename !== 'string') {
return Promise.reject(errors_1.Errors.FilenameNotProvided());
}
filename = (0, common_1.maybeFileURLToPath)(filename);
let signal;
if (this.closingUp) {
const closingUpAbortController = new AbortController();
closingUpAbortController.abort('queue is closing up');
signal = closingUpAbortController.signal;
}
else {
signal = (_a = options.signal) !== null && _a !== void 0 ? _a : null;
}
let resolve;
let reject;
// eslint-disable-next-line
const ret = new Promise((res, rej) => { resolve = res; reject = rej; });
const taskInfo = new task_queue_1.TaskInfo(task, transferList, filename, name, (err, result) => {
var _a;
this.completed++;
if (taskInfo.started) {
(_a = this.runTime) === null || _a === void 0 ? void 0 : _a.record((0, common_1.toHistogramIntegerNano)(node_perf_hooks_1.performance.now() - taskInfo.started));
}
if (err !== null) {
reject(err);
}
else {
resolve(result);
}
this._maybeDrain();
}, signal, this.publicInterface.asyncResource.asyncId());
if (signal !== null) {
// If the AbortSignal has an aborted property and it's truthy,
// reject immediately.
if (signal.aborted) {
return Promise.reject(new abort_1.AbortError(signal.reason));
}
taskInfo.abortListener = () => {
// Call reject() first to make sure we always reject with the AbortError
// if the task is aborted, not with an Error from the possible
// thread termination below.
reject(new abort_1.AbortError(signal.reason));
if (taskInfo.workerInfo !== null) {
// Already running: We cancel the Worker this is running on.
this._removeWorker(taskInfo.workerInfo);
this._ensureMinimumWorkers();
}
else {
// Not yet running: Remove it from the queue.
this.taskQueue.remove(taskInfo);
}
};
(0, abort_1.onabort)(signal, taskInfo.abortListener);
}
// If there is a task queue, there's no point in looking for an available
// Worker thread. Add this task to the queue, if possible.
if (this.taskQueue.size > 0) {
const totalCapacity = this.options.maxQueue + this.pendingCapacity();
if (this.taskQueue.size >= totalCapacity) {
if (this.options.maxQueue === 0) {
return Promise.reject(errors_1.Errors.NoTaskQueueAvailable());
}
else {
return Promise.reject(errors_1.Errors.TaskQueueAtLimit());
}
}
else {
if (this.workers.size < this.options.maxThreads) {
this._addNewWorker();
}
this.taskQueue.push(taskInfo);
}
this._maybeDrain();
return ret;
}
// Look for a Worker with a minimum number of tasks it is currently running.
let workerInfo = this.workers.findAvailable();
// If we want the ability to abort this task, use only workers that have
// no running tasks.
if (workerInfo !== null && workerInfo.currentUsage() > 0 && signal) {
workerInfo = null;
}
// If no Worker was found, or that Worker was handling another task in some
// way, and we still have the ability to spawn new threads, do so.
let waitingForNewWorker = false;
if ((workerInfo === null || workerInfo.currentUsage() > 0) &&
this.workers.size < this.options.maxThreads) {
this._addNewWorker();
waitingForNewWorker = true;
}
// If no Worker is found, try to put the task into the queue.
if (workerInfo === null) {
if (this.options.maxQueue <= 0 && !waitingForNewWorker) {
return Promise.reject(errors_1.Errors.NoTaskQueueAvailable());
}
else {
this.taskQueue.push(taskInfo);
}
this._maybeDrain();
return ret;
}
// TODO(addaleax): Clean up the waitTime/runTime recording.
const now = node_perf_hooks_1.performance.now();
(_b = this.waitTime) === null || _b === void 0 ? void 0 : _b.record((0, common_1.toHistogramIntegerNano)(now - taskInfo.created));
taskInfo.started = now;
workerInfo.postTask(taskInfo);
this._maybeDrain();
return ret;
}
pendingCapacity() {
return this.workers.pendingItems.size *
this.options.concurrentTasksPerWorker;
}
_maybeDrain() {
const totalCapacity = this.options.maxQueue + this.pendingCapacity();
const totalQueueSize = this.taskQueue.size + this.skipQueue.length;
if (totalQueueSize === 0) {
this.needsDrain = false;
this.publicInterface.emit('drain');
}
if (totalQueueSize >= totalCapacity) {
this.needsDrain = true;
this.publicInterface.emit('needsDrain');
}
}
async destroy() {
this.destroying = true;
while (this.skipQueue.length > 0) {
const taskInfo = this.skipQueue.shift();
taskInfo.done(new Error('Terminating worker thread'));
}
while (this.taskQueue.size > 0) {
const taskInfo = this.taskQueue.shift();
taskInfo.done(new Error('Terminating worker thread'));
}
const exitEvents = [];
while (this.workers.size > 0) {
const [workerInfo] = this.workers;
exitEvents.push((0, node_events_1.once)(workerInfo.worker, 'exit'));
this._removeWorker(workerInfo);
}
try {
await Promise.all(exitEvents);
}
finally {
this.destroying = false;
}
}
async close(options) {
this.closingUp = true;
if (options.force) {
const skipQueueLength = this.skipQueue.length;
for (let i = 0; i < skipQueueLength; i++) {
const taskInfo = this.skipQueue.shift();
if (taskInfo.workerInfo === null) {
taskInfo.done(new abort_1.AbortError('pool is closed'));
}
else {
this.skipQueue.push(taskInfo);
}
}
const taskQueueLength = this.taskQueue.size;
for (let i = 0; i < taskQueueLength; i++) {
const taskInfo = this.taskQueue.shift();
if (taskInfo.workerInfo === null) {
taskInfo.done(new abort_1.AbortError('pool is closed'));
}
else {
this.taskQueue.push(taskInfo);
}
}
}
const onPoolFlushed = () => new Promise((resolve) => {
const numberOfWorkers = this.workers.size;
if (numberOfWorkers === 0) {
resolve();
return;
}
let numberOfWorkersDone = 0;
const checkIfWorkerIsDone = (workerInfo) => {
if (workerInfo.taskInfos.size === 0) {
numberOfWorkersDone++;
}
if (numberOfWorkers === numberOfWorkersDone) {
resolve();
}
};
for (const workerInfo of this.workers) {
checkIfWorkerIsDone(workerInfo);
workerInfo.port.on('message', () => checkIfWorkerIsDone(workerInfo));
}
});
const throwOnTimeOut = async (timeout) => {
await (0, promises_1.setTimeout)(timeout);
throw errors_1.Errors.CloseTimeout();
};
try {
await Promise.race([
onPoolFlushed(),
throwOnTimeOut(this.options.closeTimeout)
]);
}
catch (error) {
this.publicInterface.emit('error', error);
}
finally {
await this.destroy();
this.publicInterface.emit('close');
this.closingUp = false;
}
}
}
class Piscina extends node_events_1.EventEmitterAsyncResource {
constructor(options = {}) {
super({ ...options, name: 'Piscina' });
_Piscina_pool.set(this, void 0);
if (typeof options.filename !== 'string' && options.filename != null) {
throw new TypeError('options.filename must be a string or null');
}
if (typeof options.name !== 'string' && options.name != null) {
throw new TypeError('options.name must be a string or null');
}
if (options.minThreads !== undefined &&
(typeof options.minThreads !== 'number' || options.minThreads < 0)) {
throw new TypeError('options.minThreads must be a non-negative integer');
}
if (options.maxThreads !== undefined &&
(typeof options.maxThreads !== 'number' || options.maxThreads < 1)) {
throw new TypeError('options.maxThreads must be a positive integer');
}
if (options.minThreads !== undefined && options.maxThreads !== undefined &&
options.minThreads > options.maxThreads) {
throw new RangeError('options.minThreads and options.maxThreads must not conflict');
}
if (options.idleTimeout !== undefined &&
(typeof options.idleTimeout !== 'number' || options.idleTimeout < 0)) {
throw new TypeError('options.idleTimeout must be a non-negative integer');
}
if (options.maxQueue !== undefined &&
options.maxQueue !== 'auto' &&
(typeof options.maxQueue !== 'number' || options.maxQueue < 0)) {
throw new TypeError('options.maxQueue must be a non-negative integer');
}
if (options.concurrentTasksPerWorker !== undefined &&
(typeof options.concurrentTasksPerWorker !== 'number' ||
options.concurrentTasksPerWorker < 1)) {
throw new TypeError('options.concurrentTasksPerWorker must be a positive integer');
}
if (options.useAtomics !== undefined &&
typeof options.useAtomics !== 'boolean') {
throw new TypeError('options.useAtomics must be a boolean value');
}
if (options.resourceLimits !== undefined &&
(typeof options.resourceLimits !== 'object' ||
options.resourceLimits === null)) {
throw new TypeError('options.resourceLimits must be an object');
}
if (options.taskQueue !== undefined && !(0, task_queue_1.isTaskQueue)(options.taskQueue)) {
throw new TypeError('options.taskQueue must be a TaskQueue object');
}
if (options.niceIncrement !== undefined &&
(typeof options.niceIncrement !== 'number' || (options.niceIncrement < 0 && process.platform !== 'win32'))) {
throw new TypeError('options.niceIncrement must be a non-negative integer on Unix systems');
}
if (options.trackUnmanagedFds !== undefined &&
typeof options.trackUnmanagedFds !== 'boolean') {
throw new TypeError('options.trackUnmanagedFds must be a boolean value');
}
if (options.closeTimeout !== undefined && (typeof options.closeTimeout !== 'number' || options.closeTimeout < 0)) {
throw new TypeError('options.closeTimeout must be a non-negative integer');
}
__classPrivateFieldSet(this, _Piscina_pool, new ThreadPool(this, options), "f");
}
/** @deprecated Use run(task, options) instead **/
runTask(task, transferList, filename, signal) {
// If transferList is a string or AbortSignal, shift it.
if ((typeof transferList === 'object' && !Array.isArray(transferList)) ||
typeof transferList === 'string') {
signal = filename;
filename = transferList;
transferList = undefined;
}
// If filename is an AbortSignal, shift it.
if (typeof filename === 'object' && !Array.isArray(filename)) {
signal = filename;
filename = undefined;
}
if (transferList !== undefined && !Array.isArray(transferList)) {
return Promise.reject(new TypeError('transferList argument must be an Array'));
}
if (filename !== undefined && typeof filename !== 'string') {
return Promise.reject(new TypeError('filename argument must be a string'));
}
if (signal !== undefined && typeof signal !== 'object') {
return Promise.reject(new TypeError('signal argument must be an object'));
}
return __classPrivateFieldGet(this, _Piscina_pool, "f").runTask(task, {
transferList,
filename: filename || null,
name: 'default',
signal: signal || null
});
}
run(task, options = kDefaultRunOptions) {
if (options === null || typeof options !== 'object') {
return Promise.reject(new TypeError('options must be an object'));
}
const { transferList, filename, name, signal } = options;
if (transferList !== undefined && !Array.isArray(transferList)) {
return Promise.reject(new TypeError('transferList argument must be an Array'));
}
if (filename != null && typeof filename !== 'string') {
return Promise.reject(new TypeError('filename argument must be a string'));
}
if (name != null && typeof name !== 'string') {
return Promise.reject(new TypeError('name argument must be a string'));
}
if (signal != null && typeof signal !== 'object') {
return Promise.reject(new TypeError('signal argument must be an object'));
}
return __classPrivateFieldGet(this, _Piscina_pool, "f").runTask(task, { transferList, filename, name, signal });
}
async close(options = kDefaultCloseOptions) {
if (options === null || typeof options !== 'object') {
throw TypeError('options must be an object');
}
let { force } = options;
if (force !== undefined && typeof force !== 'boolean') {
return Promise.reject(new TypeError('force argument must be a boolean'));
}
force !== null && force !== void 0 ? force : (force = kDefaultCloseOptions.force);
return __classPrivateFieldGet(this, _Piscina_pool, "f").close({
force
});
}
destroy() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").destroy();
}
get maxThreads() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").options.maxThreads;
}
get minThreads() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").options.minThreads;
}
get options() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").options;
}
get threads() {
const ret = [];
for (const workerInfo of __classPrivateFieldGet(this, _Piscina_pool, "f").workers) {
ret.push(workerInfo.worker);
}
return ret;
}
get queueSize() {
const pool = __classPrivateFieldGet(this, _Piscina_pool, "f");
return Math.max(pool.taskQueue.size - pool.pendingCapacity(), 0);
}
get completed() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").completed;
}
get waitTime() {
if (!__classPrivateFieldGet(this, _Piscina_pool, "f").waitTime) {
return null;
}
return (0, common_1.createHistogramSummary)(__classPrivateFieldGet(this, _Piscina_pool, "f").waitTime);
}
get runTime() {
if (!__classPrivateFieldGet(this, _Piscina_pool, "f").runTime) {
return null;
}
return (0, common_1.createHistogramSummary)(__classPrivateFieldGet(this, _Piscina_pool, "f").runTime);
}
get utilization() {
if (!__classPrivateFieldGet(this, _Piscina_pool, "f").runTime) {
return 0;
}
// count is available as of Node.js v16.14.0 but not present in the types
const count = __classPrivateFieldGet(this, _Piscina_pool, "f").runTime.count;
if (count === 0) {
return 0;
}
// The capacity is the max compute time capacity of the
// pool to this point in time as determined by the length
// of time the pool has been running multiplied by the
// maximum number of threads.
const capacity = this.duration * __classPrivateFieldGet(this, _Piscina_pool, "f").options.maxThreads;
const totalMeanRuntime = (__classPrivateFieldGet(this, _Piscina_pool, "f").runTime.mean / 1000) * count;
// We calculate the appoximate pool utilization by multiplying
// the mean run time of all tasks by the number of runtime
// samples taken and dividing that by the capacity. The
// theory here is that capacity represents the absolute upper
// limit of compute time this pool could ever attain (but
// never will for a variety of reasons. Multiplying the
// mean run time by the number of tasks sampled yields an
// approximation of the realized compute time. The utilization
// then becomes a point-in-time measure of how active the
// pool is.
return totalMeanRuntime / capacity;
}
get duration() {
return node_perf_hooks_1.performance.now() - __classPrivateFieldGet(this, _Piscina_pool, "f").start;
}
get needsDrain() {
return __classPrivateFieldGet(this, _Piscina_pool, "f").needsDrain;
}
static get isWorkerThread() {
return common_1.commonState.isWorkerThread;
}
static get workerData() {
return common_1.commonState.workerData;
}
static get version() {
return package_json_1.version;
}
static get Piscina() {
return Piscina;
}
static get FixedQueue() {
return task_queue_1.FixedQueue;
}
static get ArrayTaskQueue() {
return task_queue_1.ArrayTaskQueue;
}
static move(val) {
if (val != null && typeof val === 'object' && typeof val !== 'function') {
if (!(0, common_1.isTransferable)(val)) {
if (node_util_1.types.isArrayBufferView(val)) {
val = new ArrayBufferViewTransferable(val);
}
else {
val = new DirectlyTransferable(val);
}
}
(0, common_1.markMovable)(val);
}
return val;
}
static get transferableSymbol() { return symbols_1.kTransferable; }
static get valueSymbol() { return symbols_1.kValue; }
static get queueOptionsSymbol() { return symbols_1.kQueueOptions; }
}
exports.Piscina = Piscina;
_Piscina_pool = new WeakMap();
exports.default = Piscina;
exports.move = Piscina.move;
exports.isWorkerThread = Piscina.isWorkerThread;
exports.workerData = Piscina.workerData;
//# sourceMappingURL=index.js.map

1
node_modules/piscina/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

2
node_modules/piscina/dist/main.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import Piscina from './index';
export = Piscina;

7
node_modules/piscina/dist/main.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const index_1 = __importDefault(require("./index"));
module.exports = index_1.default;
//# sourceMappingURL=main.js.map

1
node_modules/piscina/dist/main.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAG9B,iBAAS,eAAO,CAAC"}

7
node_modules/piscina/dist/symbols.d.ts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
export declare const kMovable: unique symbol;
export declare const kTransferable: unique symbol;
export declare const kValue: unique symbol;
export declare const kQueueOptions: unique symbol;
export declare const kRequestCountField = 0;
export declare const kResponseCountField = 1;
export declare const kFieldCount = 2;

13
node_modules/piscina/dist/symbols.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.kFieldCount = exports.kResponseCountField = exports.kRequestCountField = exports.kQueueOptions = exports.kValue = exports.kTransferable = exports.kMovable = void 0;
// Internal symbol used to mark Transferable objects returned
// by the Piscina.move() function
exports.kMovable = Symbol('Piscina.kMovable');
exports.kTransferable = Symbol.for('Piscina.transferable');
exports.kValue = Symbol.for('Piscina.valueOf');
exports.kQueueOptions = Symbol.for('Piscina.queueOptions');
exports.kRequestCountField = 0;
exports.kResponseCountField = 1;
exports.kFieldCount = 2;
//# sourceMappingURL=symbols.js.map

1
node_modules/piscina/dist/symbols.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../src/symbols.ts"],"names":[],"mappings":";;;AAAA,6DAA6D;AAC7D,iCAAiC;AACpB,QAAA,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AACtC,QAAA,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AACnD,QAAA,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AACvC,QAAA,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AACnD,QAAA,kBAAkB,GAAG,CAAC,CAAC;AACvB,QAAA,mBAAmB,GAAG,CAAC,CAAC;AACxB,QAAA,WAAW,GAAG,CAAC,CAAC"}

View File

@@ -0,0 +1,8 @@
import type { TaskQueue, Task } from '.';
export declare class ArrayTaskQueue implements TaskQueue {
tasks: Task[];
get size(): number;
shift(): Task | null;
push(task: Task): void;
remove(task: Task): void;
}

29
node_modules/piscina/dist/task_queue/array_queue.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayTaskQueue = void 0;
const node_assert_1 = __importDefault(require("node:assert"));
class ArrayTaskQueue {
constructor() {
this.tasks = [];
}
get size() {
return this.tasks.length;
}
shift() {
var _a;
return (_a = this.tasks.shift()) !== null && _a !== void 0 ? _a : null;
}
push(task) {
this.tasks.push(task);
}
remove(task) {
const index = this.tasks.indexOf(task);
node_assert_1.default.notStrictEqual(index, -1);
this.tasks.splice(index, 1);
}
}
exports.ArrayTaskQueue = ArrayTaskQueue;
//# sourceMappingURL=array_queue.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"array_queue.js","sourceRoot":"","sources":["../../src/task_queue/array_queue.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAIjC,MAAa,cAAc;IAA3B;QACE,UAAK,GAAW,EAAE,CAAA;IAmBpB,CAAC;IAjBC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,KAAK;;QACH,OAAO,MAAA,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,mCAAI,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,CAAE,IAAU;QACd,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,CAAE,IAAU;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,qBAAM,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC9B,CAAC;CACF;AApBD,wCAoBC"}

17
node_modules/piscina/dist/task_queue/common.d.ts generated vendored Normal file
View File

@@ -0,0 +1,17 @@
import type { kQueueOptions } from '../symbols';
export interface TaskQueue {
readonly size: number;
shift(): Task | null;
remove(task: Task): void;
push(task: Task): void;
}
export interface PiscinaTask extends Task {
taskId: number;
filename: string;
name: string;
created: number;
isAbortable: boolean;
}
export interface Task {
readonly [kQueueOptions]: object | null;
}

4
node_modules/piscina/dist/task_queue/common.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
//# sourceMappingURL=common.js.map

1
node_modules/piscina/dist/task_queue/common.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/task_queue/common.ts"],"names":[],"mappings":";;AAoBC,CAAC"}

26
node_modules/piscina/dist/task_queue/fixed_queue.d.ts generated vendored Normal file
View File

@@ -0,0 +1,26 @@
import type { Task } from './common';
import { TaskQueue } from '.';
declare class FixedCircularBuffer {
bottom: number;
top: number;
list: Array<Task | undefined>;
next: FixedCircularBuffer | null;
constructor();
isEmpty(): boolean;
isFull(): boolean;
push(data: Task): void;
shift(): Task | null;
remove(task: Task): void;
}
export declare class FixedQueue implements TaskQueue {
head: FixedCircularBuffer;
tail: FixedCircularBuffer;
_size: number;
constructor();
isEmpty(): boolean;
push(data: Task): void;
shift(): Task | null;
remove(task: Task): void;
get size(): number;
}
export {};

176
node_modules/piscina/dist/task_queue/fixed_queue.js generated vendored Normal file
View File

@@ -0,0 +1,176 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixedQueue = void 0;
/*
* Modified Fixed Queue Implementation based on the one from Node.js Project
* License: MIT License
* Source: https://github.com/nodejs/node/blob/de7b37880f5a541d5f874c1c2362a65a4be76cd0/lib/internal/fixed_queue.js
*/
const node_assert_1 = __importDefault(require("node:assert"));
// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
const kSize = 2048;
const kMask = kSize - 1;
// The FixedQueue is implemented as a singly-linked list of fixed-size
// circular buffers. It looks something like this:
//
// head tail
// | |
// v v
// +-----------+ <-----\ +-----------+ <------\ +-----------+
// | [null] | \----- | next | \------- | next |
// +-----------+ +-----------+ +-----------+
// | item | <-- bottom | item | <-- bottom | [empty] |
// | item | | item | | [empty] |
// | item | | item | | [empty] |
// | item | | item | | [empty] |
// | item | | item | bottom --> | item |
// | item | | item | | item |
// | ... | | ... | | ... |
// | item | | item | | item |
// | item | | item | | item |
// | [empty] | <-- top | item | | item |
// | [empty] | | item | | item |
// | [empty] | | [empty] | <-- top top --> | [empty] |
// +-----------+ +-----------+ +-----------+
//
// Or, if there is only one circular buffer, it looks something
// like either of these:
//
// head tail head tail
// | | | |
// v v v v
// +-----------+ +-----------+
// | [null] | | [null] |
// +-----------+ +-----------+
// | [empty] | | item |
// | [empty] | | item |
// | item | <-- bottom top --> | [empty] |
// | item | | [empty] |
// | [empty] | <-- top bottom --> | item |
// | [empty] | | item |
// +-----------+ +-----------+
//
// Adding a value means moving `top` forward by one, removing means
// moving `bottom` forward by one. After reaching the end, the queue
// wraps around.
//
// When `top === bottom` the current queue is empty and when
// `top + 1 === bottom` it's full. This wastes a single space of storage
// but allows much quicker checks.
class FixedCircularBuffer {
constructor() {
this.bottom = 0;
this.top = 0;
this.list = new Array(kSize);
this.next = null;
}
isEmpty() {
return this.top === this.bottom;
}
isFull() {
return ((this.top + 1) & kMask) === this.bottom;
}
push(data) {
this.list[this.top] = data;
this.top = (this.top + 1) & kMask;
}
shift() {
const nextItem = this.list[this.bottom];
if (nextItem === undefined) {
return null;
}
this.list[this.bottom] = undefined;
this.bottom = (this.bottom + 1) & kMask;
return nextItem;
}
remove(task) {
const indexToRemove = this.list.indexOf(task);
node_assert_1.default.notStrictEqual(indexToRemove, -1);
let curr = indexToRemove;
while (true) {
const next = (curr + 1) & kMask;
this.list[curr] = this.list[next];
if (this.list[curr] === undefined) {
break;
}
if (next === indexToRemove) {
this.list[curr] = undefined;
break;
}
curr = next;
}
this.top = (this.top - 1) & kMask;
}
}
class FixedQueue {
constructor() {
this._size = 0;
this.head = this.tail = new FixedCircularBuffer();
}
isEmpty() {
return this.head.isEmpty();
}
push(data) {
if (this.head.isFull()) {
// Head is full: Creates a new queue, sets the old queue's `.next` to it,
// and sets it as the new main queue.
this.head = this.head.next = new FixedCircularBuffer();
}
this.head.push(data);
this._size++;
}
shift() {
const tail = this.tail;
const next = tail.shift();
if (next !== null)
this._size--;
if (tail.isEmpty() && tail.next !== null) {
// If there is another queue, it forms the new tail.
this.tail = tail.next;
tail.next = null;
}
return next;
}
remove(task) {
let prev = null;
let buffer = this.tail;
while (true) {
if (buffer.list.includes(task)) {
buffer.remove(task);
this._size--;
break;
}
if (buffer.next === null)
break;
prev = buffer;
buffer = buffer.next;
}
if (buffer.isEmpty()) {
// removing tail
if (prev === null) {
// if tail is not the last buffer
if (buffer.next !== null)
this.tail = buffer.next;
}
else {
// removing head
if (buffer.next === null) {
this.head = prev;
}
else {
// removing buffer from middle
prev.next = buffer.next;
}
}
}
}
get size() {
return this._size;
}
}
exports.FixedQueue = FixedQueue;
;
//# sourceMappingURL=fixed_queue.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fixed_queue.js","sourceRoot":"","sources":["../../src/task_queue/fixed_queue.ts"],"names":[],"mappings":";;;;;;AAAA;;;;GAIG;AACH,8DAAiC;AAGjC,8EAA8E;AAC9E,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC;AAExB,sEAAsE;AACtE,kDAAkD;AAClD,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,kEAAkE;AAClE,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,EAAE;AACF,+DAA+D;AAC/D,wBAAwB;AACxB,EAAE;AACF,2DAA2D;AAC3D,yDAAyD;AACzD,yDAAyD;AACzD,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,4DAA4D;AAC5D,EAAE;AACF,mEAAmE;AACnE,oEAAoE;AACpE,gBAAgB;AAChB,EAAE;AACF,4DAA4D;AAC5D,wEAAwE;AACxE,kCAAkC;AAElC,MAAM,mBAAmB;IAMvB;QACE,IAAI,CAAC,MAAM,GAAG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CAAC;IACpB,CAAC;CACF;AApED,gCAoEC;AAAA,CAAC"}

40
node_modules/piscina/dist/task_queue/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,40 @@
import type { MessagePort } from 'node:worker_threads';
import { AsyncResource } from 'node:async_hooks';
import type { WorkerInfo } from '../worker_pool';
import type { AbortSignalAny } from '../abort';
import { kQueueOptions } from '../symbols';
import type { Task, TaskQueue, PiscinaTask } from './common';
export { ArrayTaskQueue } from './array_queue';
export { FixedQueue } from './fixed_queue';
export type TaskCallback = (err: Error, result: any) => void;
export type TransferList = MessagePort extends {
postMessage: (value: any, transferList: infer T) => any;
} ? T : never;
export type TransferListItem = TransferList extends Array<infer T> ? T : never;
/**
* Verifies if a given TaskQueue is valid
*
* @export
* @param {*} value
* @return {*} {boolean}
*/
export declare function isTaskQueue(value: TaskQueue): boolean;
export declare class TaskInfo extends AsyncResource implements Task {
callback: TaskCallback;
task: any;
transferList: TransferList;
filename: string;
name: string;
taskId: number;
abortSignal: AbortSignalAny | null;
abortListener: (() => void) | null;
workerInfo: WorkerInfo | null;
created: number;
started: number;
constructor(task: any, transferList: TransferList, filename: string, name: string, callback: TaskCallback, abortSignal: AbortSignalAny | null, triggerAsyncId: number);
releaseTask(): any;
done(err: Error | null, result?: any): void;
get [kQueueOptions](): object | null;
get interface(): PiscinaTask;
}
export { Task, TaskQueue, PiscinaTask };

94
node_modules/piscina/dist/task_queue/index.js generated vendored Normal file
View File

@@ -0,0 +1,94 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskInfo = exports.FixedQueue = exports.ArrayTaskQueue = void 0;
exports.isTaskQueue = isTaskQueue;
const node_perf_hooks_1 = require("node:perf_hooks");
const node_async_hooks_1 = require("node:async_hooks");
const common_1 = require("../common");
const symbols_1 = require("../symbols");
var array_queue_1 = require("./array_queue");
Object.defineProperty(exports, "ArrayTaskQueue", { enumerable: true, get: function () { return array_queue_1.ArrayTaskQueue; } });
var fixed_queue_1 = require("./fixed_queue");
Object.defineProperty(exports, "FixedQueue", { enumerable: true, get: function () { return fixed_queue_1.FixedQueue; } });
/**
* Verifies if a given TaskQueue is valid
*
* @export
* @param {*} value
* @return {*} {boolean}
*/
function isTaskQueue(value) {
return (typeof value === 'object' &&
value !== null &&
'size' in value &&
typeof value.shift === 'function' &&
typeof value.remove === 'function' &&
typeof value.push === 'function');
}
let taskIdCounter = 0;
// Extend AsyncResource so that async relations between posting a task and
// receiving its result are visible to diagnostic tools.
class TaskInfo extends node_async_hooks_1.AsyncResource {
constructor(task, transferList, filename, name, callback, abortSignal, triggerAsyncId) {
super('Piscina.Task', { requireManualDestroy: true, triggerAsyncId });
this.abortListener = null;
this.workerInfo = null;
this.callback = callback;
this.task = task;
this.transferList = transferList;
// If the task is a Transferable returned by
// Piscina.move(), then add it to the transferList
// automatically
if ((0, common_1.isMovable)(task)) {
// This condition should never be hit but typescript
// complains if we dont do the check.
/* istanbul ignore if */
if (this.transferList == null) {
this.transferList = [];
}
this.transferList =
this.transferList.concat(task[symbols_1.kTransferable]);
this.task = task[symbols_1.kValue];
}
this.filename = filename;
this.name = name;
this.taskId = taskIdCounter++;
this.abortSignal = abortSignal;
this.created = node_perf_hooks_1.performance.now();
this.started = 0;
}
releaseTask() {
const ret = this.task;
this.task = null;
return ret;
}
done(err, result) {
this.runInAsyncScope(this.callback, null, err, result);
this.emitDestroy(); // `TaskInfo`s are used only once.
// If an abort signal was used, remove the listener from it when
// done to make sure we do not accidentally leak.
if (this.abortSignal && this.abortListener) {
if ('removeEventListener' in this.abortSignal && this.abortListener) {
this.abortSignal.removeEventListener('abort', this.abortListener);
}
else {
this.abortSignal.off('abort', this.abortListener);
}
}
}
get [symbols_1.kQueueOptions]() {
return symbols_1.kQueueOptions in this.task ? this.task[symbols_1.kQueueOptions] : null;
}
get interface() {
return {
taskId: this.taskId,
filename: this.filename,
name: this.name,
created: this.created,
isAbortable: this.abortSignal !== null,
[symbols_1.kQueueOptions]: this[symbols_1.kQueueOptions]
};
}
}
exports.TaskInfo = TaskInfo;
//# sourceMappingURL=index.js.map

1
node_modules/piscina/dist/task_queue/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/task_queue/index.ts"],"names":[],"mappings":";;;AAgCA,kCASC;AAxCD,qDAA8C;AAC9C,uDAAiD;AAIjD,sCAAsC;AACtC,wCAAkE;AAIlE,6CAA+C;AAAtC,6GAAA,cAAc,OAAA;AACvB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AAanB;;;;;;GAMG;AACH,SAAgB,WAAW,CAAE,KAAgB;IAC3C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU;QACjC,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU;QAClC,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CACjC,CAAC;AACJ,CAAC;AAED,IAAI,aAAa,GAAG,CAAC,CAAC;AACtB,0EAA0E;AAC1E,wDAAwD;AACxD,MAAa,QAAS,SAAQ,gCAAa;IAavC,YACE,IAAU,EACV,YAA2B,EAC3B,QAAiB,EACjB,IAAa,EACb,QAAuB,EACvB,WAAmC,EACnC,cAAuB;QACvB,KAAK,CAAC,cAAc,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QAbxE,kBAAa,GAAyB,IAAI,CAAC;QAC3C,eAAU,GAAuB,IAAI,CAAC;QAapC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,4CAA4C;QAC5C,kDAAkD;QAClD,gBAAgB;QAChB,IAAI,IAAA,kBAAS,EAAC,IAAI,CAAC,EAAE,CAAC;YACpB,oDAAoD;YACpD,qCAAqC;YACrC,wBAAwB;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C,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,CAAC,uBAAa,CAAC;QACjB,OAAO,uBAAa,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtE,CAAC;IAED,IAAI,SAAS;QACX,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW,KAAK,IAAI;YACtC,CAAC,uBAAa,CAAC,EAAE,IAAI,CAAC,uBAAa,CAAC;SACrC,CAAC;IACJ,CAAC;CACJ;AApFD,4BAoFC"}

63
node_modules/piscina/dist/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,63 @@
import type { MessagePort, Worker } from 'node:worker_threads';
import type { READY } from './common';
import type { kTransferable, kValue } from './symbols';
export interface StartupMessage {
filename: string | null;
name: string;
port: MessagePort;
sharedBuffer: Int32Array;
useAtomics: boolean;
niceIncrement: number;
}
export interface RequestMessage {
taskId: number;
task: any;
filename: string;
name: string;
}
export interface ReadyMessage {
[READY]: true;
}
export interface ResponseMessage {
taskId: number;
result: any;
error: Error | null;
}
export declare const commonState: {
isWorkerThread: boolean;
workerData: undefined;
};
export interface Transferable {
readonly [kTransferable]: object;
readonly [kValue]: object;
}
export interface HistogramSummary {
average: number;
mean: number;
stddev: number;
min: number;
max: number;
p0_001: number;
p0_01: number;
p0_1: number;
p1: number;
p2_5: number;
p10: number;
p25: number;
p50: number;
p75: number;
p90: number;
p97_5: number;
p99: number;
p99_9: number;
p99_99: number;
p99_999: number;
}
export type ResourceLimits = Worker extends {
resourceLimits?: infer T;
} ? T : {};
export type EnvSpecifier = typeof Worker extends {
new (filename: never, options?: {
env: infer T;
}): Worker;
} ? T : never;

8
node_modules/piscina/dist/types.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.commonState = void 0;
exports.commonState = {
isWorkerThread: false,
workerData: undefined
};
//# sourceMappingURL=types.js.map

1
node_modules/piscina/dist/types.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA8Ba,QAAA,WAAW,GAAG;IACzB,cAAc,EAAE,KAAK;IACrB,UAAU,EAAE,SAAS;CACtB,CAAC"}

1
node_modules/piscina/dist/worker.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

186
node_modules/piscina/dist/worker.js generated vendored Normal file
View File

@@ -0,0 +1,186 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_worker_threads_1 = require("node:worker_threads");
const node_url_1 = require("node:url");
const symbols_1 = require("./symbols");
const common_1 = require("./common");
common_1.commonState.isWorkerThread = true;
common_1.commonState.workerData = node_worker_threads_1.workerData;
const handlerCache = new Map();
let useAtomics = process.env.PISCINA_DISABLE_ATOMICS !== '1';
// Get `import(x)` as a function that isn't transpiled to `require(x)` by
// TypeScript for dual ESM/CJS support.
// Load this lazily, so that there is no warning about the ESM loader being
// experimental (on Node v12.x) until we actually try to use it.
let importESMCached;
function getImportESM() {
if (importESMCached === undefined) {
// eslint-disable-next-line no-new-func
importESMCached = new Function('specifier', 'return import(specifier)');
}
return importESMCached;
}
// Look up the handler function that we call when a task is posted.
// This is either going to be "the" export from a file, or the default export.
async function getHandler(filename, name) {
let handler = handlerCache.get(`${filename}/${name}`);
if (handler !== undefined) {
return handler;
}
try {
// With our current set of TypeScript options, this is transpiled to
// `require(filename)`.
handler = await Promise.resolve(`${filename}`).then(s => __importStar(require(s)));
if (typeof handler !== 'function') {
handler = await (handler[name]);
}
}
catch { }
if (typeof handler !== 'function') {
handler = await getImportESM()((0, node_url_1.pathToFileURL)(filename).href);
if (typeof handler !== 'function') {
handler = await (handler[name]);
}
}
if (typeof handler !== 'function') {
return null;
}
// Limit the handler cache size. This should not usually be an issue and is
// only provided for pathological cases.
if (handlerCache.size > 1000) {
const [[key]] = handlerCache;
handlerCache.delete(key);
}
handlerCache.set(`${filename}/${name}`, handler);
return handler;
}
// We should only receive this message once, when the Worker starts. It gives
// us the MessagePort used for receiving tasks, a SharedArrayBuffer for fast
// communication using Atomics, and the name of the default filename for tasks
// (so we can pre-load and cache the handler).
node_worker_threads_1.parentPort.on('message', (message) => {
useAtomics = process.env.PISCINA_DISABLE_ATOMICS === '1' ? false : message.useAtomics;
const { port, sharedBuffer, filename, name, niceIncrement } = message;
(async function () {
try {
if (niceIncrement !== 0) {
(await Promise.resolve().then(() => __importStar(require('@napi-rs/nice')))).nice(niceIncrement);
}
}
catch { }
if (filename !== null) {
await getHandler(filename, name);
}
const readyMessage = { [common_1.READY]: true };
node_worker_threads_1.parentPort.postMessage(readyMessage);
port.on('message', onMessage.bind(null, port, sharedBuffer));
atomicsWaitLoop(port, sharedBuffer);
})().catch(throwInNextTick);
});
let currentTasks = 0;
let lastSeenRequestCount = 0;
function atomicsWaitLoop(port, sharedBuffer) {
if (!useAtomics)
return;
// This function is entered either after receiving the startup message, or
// when we are done with a task. In those situations, the *only* thing we
// expect to happen next is a 'message' on `port`.
// That call would come with the overhead of a C++ → JS boundary crossing,
// including async tracking. So, instead, if there is no task currently
// running, we wait for a signal from the parent thread using Atomics.wait(),
// and read the message from the port instead of generating an event,
// in order to avoid that overhead.
// The one catch is that this stops asynchronous operations that are still
// running from proceeding. Generally, tasks should not spawn asynchronous
// operations without waiting for them to finish, though.
while (currentTasks === 0) {
// Check whether there are new messages by testing whether the current
// number of requests posted by the parent thread matches the number of
// requests received.
Atomics.wait(sharedBuffer, symbols_1.kRequestCountField, lastSeenRequestCount);
lastSeenRequestCount = Atomics.load(sharedBuffer, symbols_1.kRequestCountField);
// We have to read messages *after* updating lastSeenRequestCount in order
// to avoid race conditions.
let entry;
while ((entry = (0, node_worker_threads_1.receiveMessageOnPort)(port)) !== undefined) {
onMessage(port, sharedBuffer, entry.message);
}
}
}
function onMessage(port, sharedBuffer, message) {
currentTasks++;
const { taskId, task, filename, name } = message;
(async function () {
let response;
let transferList = [];
try {
const handler = await getHandler(filename, name);
if (handler === null) {
throw new Error(`No handler function exported from ${filename}`);
}
let result = await handler(task);
if ((0, common_1.isMovable)(result)) {
transferList = transferList.concat(result[symbols_1.kTransferable]);
result = result[symbols_1.kValue];
}
response = {
taskId,
result: result,
error: null
};
// If the task used e.g. console.log(), wait for the stream to drain
// before potentially entering the `Atomics.wait()` loop, and before
// returning the result so that messages will always be printed even
// if the process would otherwise be ready to exit.
if (process.stdout.writableLength > 0) {
await new Promise((resolve) => process.stdout.write('', resolve));
}
if (process.stderr.writableLength > 0) {
await new Promise((resolve) => process.stderr.write('', resolve));
}
}
catch (error) {
response = {
taskId,
result: null,
// It may be worth taking a look at the error cloning algorithm we
// use in Node.js core here, it's quite a bit more flexible
error: error
};
}
currentTasks--;
// Post the response to the parent thread, and let it know that we have
// an additional message available. If possible, use Atomics.wait()
// to wait for the next message.
port.postMessage(response, transferList);
Atomics.add(sharedBuffer, symbols_1.kResponseCountField, 1);
atomicsWaitLoop(port, sharedBuffer);
})().catch(throwInNextTick);
}
function throwInNextTick(error) {
process.nextTick(() => { throw error; });
}
//# sourceMappingURL=worker.js.map

1
node_modules/piscina/dist/worker.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAAgG;AAChG,uCAAyC;AAQzC,uCAKmB;AACnB,qCAIkB;AAElB,oBAAW,CAAC,cAAc,GAAG,IAAI,CAAC;AAClC,oBAAW,CAAC,UAAU,GAAG,gCAAU,CAAC;AAEpC,MAAM,YAAY,GAA2B,IAAI,GAAG,EAAE,CAAC;AACvD,IAAI,UAAU,GAAa,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,GAAG,CAAC;AAEvE,yEAAyE;AACzE,uCAAuC;AACvC,2EAA2E;AAC3E,gEAAgE;AAChE,IAAI,eAAkE,CAAC;AACvE,SAAS,YAAY;IACnB,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,uCAAuC;QACvC,eAAe,GAAG,IAAI,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAA2B,CAAC;IACpG,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,mEAAmE;AACnE,8EAA8E;AAC9E,KAAK,UAAU,UAAU,CAAE,QAAiB,EAAE,IAAa;IACzD,IAAI,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IACtD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,CAAC;QACH,oEAAoE;QACpE,uBAAuB;QACvB,OAAO,GAAG,yBAAa,QAAQ,uCAAC,C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,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;YACpE,CAAC;YACD,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC;gBACtC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,GAAG;gBACT,MAAM;gBACN,MAAM,EAAE,IAAI;gBACZ,kEAAkE;gBAClE,2DAA2D;gBAC3D,KAAK,EAAS,KAAK;aACpB,CAAC;QACJ,CAAC;QACD,YAAY,EAAE,CAAC;QAEf,uEAAuE;QACvE,mEAAmE;QACnE,gCAAgC;QAChC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,6BAAmB,EAAE,CAAC,CAAC,CAAC;QAClD,eAAe,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACtC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,eAAe,CAAE,KAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC"}

45
node_modules/piscina/dist/worker_pool/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,45 @@
import { Worker, MessagePort } from 'node:worker_threads';
import { ResponseMessage } from '../types';
import { TaskInfo } from '../task_queue';
type ResponseCallback = (response: ResponseMessage) => void;
declare abstract class AsynchronouslyCreatedResource {
onreadyListeners: (() => void)[] | null;
markAsReady(): void;
isReady(): boolean;
onReady(fn: () => void): void;
abstract currentUsage(): number;
}
export declare class AsynchronouslyCreatedResourcePool<T extends AsynchronouslyCreatedResource> {
pendingItems: Set<T>;
readyItems: Set<T>;
maximumUsage: number;
onAvailableListeners: ((item: T) => void)[];
constructor(maximumUsage: number);
add(item: T): void;
delete(item: T): void;
findAvailable(): T | null;
[Symbol.iterator](): Generator<T, void, unknown>;
get size(): number;
maybeAvailable(item: T): void;
onAvailable(fn: (item: T) => void): void;
}
export declare class WorkerInfo extends AsynchronouslyCreatedResource {
worker: Worker;
taskInfos: Map<number, TaskInfo>;
idleTimeout: NodeJS.Timeout | null;
port: MessagePort;
sharedBuffer: Int32Array;
lastSeenResponseCount: number;
onMessage: ResponseCallback;
constructor(worker: Worker, port: MessagePort, onMessage: ResponseCallback);
destroy(): void;
clearIdleTimeout(): void;
ref(): WorkerInfo;
unref(): WorkerInfo;
_handleResponse(message: ResponseMessage): void;
postTask(taskInfo: TaskInfo): void;
processPendingMessages(): void;
isRunningAbortableTask(): boolean;
currentUsage(): number;
}
export {};

190
node_modules/piscina/dist/worker_pool/index.js generated vendored Normal file
View File

@@ -0,0 +1,190 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkerInfo = exports.AsynchronouslyCreatedResourcePool = void 0;
const node_worker_threads_1 = require("node:worker_threads");
const node_assert_1 = __importDefault(require("node:assert"));
const errors_1 = require("../errors");
const symbols_1 = require("../symbols");
class AsynchronouslyCreatedResource {
constructor() {
this.onreadyListeners = [];
}
markAsReady() {
const listeners = this.onreadyListeners;
(0, node_assert_1.default)(listeners !== null);
this.onreadyListeners = null;
for (const listener of listeners) {
listener();
}
}
isReady() {
return this.onreadyListeners === null;
}
onReady(fn) {
if (this.onreadyListeners === null) {
fn(); // Zalgo is okay here.
return;
}
this.onreadyListeners.push(fn);
}
}
class AsynchronouslyCreatedResourcePool {
constructor(maximumUsage) {
this.pendingItems = new Set();
this.readyItems = new Set();
this.maximumUsage = maximumUsage;
this.onAvailableListeners = [];
}
add(item) {
this.pendingItems.add(item);
item.onReady(() => {
/* istanbul ignore else */
if (this.pendingItems.has(item)) {
this.pendingItems.delete(item);
this.readyItems.add(item);
this.maybeAvailable(item);
}
});
}
delete(item) {
this.pendingItems.delete(item);
this.readyItems.delete(item);
}
findAvailable() {
let minUsage = this.maximumUsage;
let candidate = null;
for (const item of this.readyItems) {
const usage = item.currentUsage();
if (usage === 0)
return item;
if (usage < minUsage) {
candidate = item;
minUsage = usage;
}
}
return candidate;
}
*[Symbol.iterator]() {
yield* this.pendingItems;
yield* this.readyItems;
}
get size() {
return this.pendingItems.size + this.readyItems.size;
}
maybeAvailable(item) {
/* istanbul ignore else */
if (item.currentUsage() < this.maximumUsage) {
for (const listener of this.onAvailableListeners) {
listener(item);
}
}
}
onAvailable(fn) {
this.onAvailableListeners.push(fn);
}
}
exports.AsynchronouslyCreatedResourcePool = AsynchronouslyCreatedResourcePool;
class WorkerInfo extends AsynchronouslyCreatedResource {
constructor(worker, port, onMessage) {
super();
this.idleTimeout = null; // eslint-disable-line no-undef
this.lastSeenResponseCount = 0;
this.worker = worker;
this.port = port;
this.port.on('message', (message) => this._handleResponse(message));
this.onMessage = onMessage;
this.taskInfos = new Map();
this.sharedBuffer = new Int32Array(new SharedArrayBuffer(symbols_1.kFieldCount * Int32Array.BYTES_PER_ELEMENT));
}
destroy() {
this.worker.terminate();
this.port.close();
this.clearIdleTimeout();
for (const taskInfo of this.taskInfos.values()) {
taskInfo.done(errors_1.Errors.ThreadTermination());
}
this.taskInfos.clear();
}
clearIdleTimeout() {
if (this.idleTimeout !== null) {
clearTimeout(this.idleTimeout);
this.idleTimeout = null;
}
}
ref() {
this.port.ref();
return this;
}
unref() {
// Note: Do not call ref()/unref() on the Worker itself since that may cause
// a hard crash, see https://github.com/nodejs/node/pull/33394.
this.port.unref();
return this;
}
_handleResponse(message) {
this.onMessage(message);
if (this.taskInfos.size === 0) {
// No more tasks running on this Worker means it should not keep the
// process running.
this.unref();
}
}
postTask(taskInfo) {
(0, node_assert_1.default)(!this.taskInfos.has(taskInfo.taskId));
const message = {
task: taskInfo.releaseTask(),
taskId: taskInfo.taskId,
filename: taskInfo.filename,
name: taskInfo.name
};
try {
this.port.postMessage(message, taskInfo.transferList);
}
catch (err) {
// This would mostly happen if e.g. message contains unserializable data
// or transferList is invalid.
taskInfo.done(err);
return;
}
taskInfo.workerInfo = this;
this.taskInfos.set(taskInfo.taskId, taskInfo);
this.ref();
this.clearIdleTimeout();
// Inform the worker that there are new messages posted, and wake it up
// if it is waiting for one.
Atomics.add(this.sharedBuffer, symbols_1.kRequestCountField, 1);
Atomics.notify(this.sharedBuffer, symbols_1.kRequestCountField, 1);
}
processPendingMessages() {
// If we *know* that there are more messages than we have received using
// 'message' events yet, then try to load and handle them synchronously,
// without the need to wait for more expensive events on the event loop.
// This would usually break async tracking, but in our case, we already have
// the extra TaskInfo/AsyncResource layer that rectifies that situation.
const actualResponseCount = Atomics.load(this.sharedBuffer, symbols_1.kResponseCountField);
if (actualResponseCount !== this.lastSeenResponseCount) {
this.lastSeenResponseCount = actualResponseCount;
let entry;
while ((entry = (0, node_worker_threads_1.receiveMessageOnPort)(this.port)) !== undefined) {
this._handleResponse(entry.message);
}
}
}
isRunningAbortableTask() {
// If there are abortable tasks, we are running one at most per Worker.
if (this.taskInfos.size !== 1)
return false;
const [[, task]] = this.taskInfos;
return task.abortSignal !== null;
}
currentUsage() {
if (this.isRunningAbortableTask())
return Infinity;
return this.taskInfos.size;
}
}
exports.WorkerInfo = WorkerInfo;
//# sourceMappingURL=index.js.map

1
node_modules/piscina/dist/worker_pool/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long