@lage-run/worker-threads-pool
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -5,3 +5,18 @@ { | ||
{ | ||
"date": "Tue, 25 Apr 2023 02:50:56 GMT", | ||
"date": "Mon, 08 May 2023 22:26:52 GMT", | ||
"tag": "@lage-run/worker-threads-pool_v0.7.0", | ||
"version": "0.7.0", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"author": "kchau@microsoft.com", | ||
"package": "@lage-run/worker-threads-pool", | ||
"commit": "5a132808f166179bc316a279c9e11a13d3a39103", | ||
"comment": "Adds ability to communicate with postMessage in the ThreadWorker" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Tue, 25 Apr 2023 02:51:19 GMT", | ||
"tag": "@lage-run/worker-threads-pool_v0.6.1", | ||
@@ -8,0 +23,0 @@ "version": "0.6.1", |
# Change Log - @lage-run/worker-threads-pool | ||
This log was last generated on Tue, 25 Apr 2023 02:50:56 GMT and should not be manually modified. | ||
This log was last generated on Mon, 08 May 2023 22:26:52 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 0.7.0 | ||
Mon, 08 May 2023 22:26:52 GMT | ||
### Minor changes | ||
- Adds ability to communicate with postMessage in the ThreadWorker (kchau@microsoft.com) | ||
## 0.6.1 | ||
Tue, 25 Apr 2023 02:50:56 GMT | ||
Tue, 25 Apr 2023 02:51:19 GMT | ||
@@ -11,0 +19,0 @@ ### Patches |
@@ -7,5 +7,20 @@ "use strict"; | ||
enumerable: true, | ||
get: ()=>AggregatedPool | ||
get: function() { | ||
return AggregatedPool; | ||
} | ||
}); | ||
const _workerPoolJs = require("./WorkerPool.js"); | ||
const _WorkerPool = require("./WorkerPool.js"); | ||
function _define_property(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
class AggregatedPool { | ||
@@ -45,2 +60,5 @@ stats() { | ||
constructor(options){ | ||
_define_property(this, "options", void 0); | ||
_define_property(this, "groupedPools", void 0); | ||
_define_property(this, "defaultPool", void 0); | ||
this.options = options; | ||
@@ -51,3 +69,3 @@ this.groupedPools = new Map(); | ||
for (const [group, groupMaxWorkers] of maxWorkersByGroup.entries()){ | ||
const pool = new _workerPoolJs.WorkerPool({ | ||
const pool = new _WorkerPool.WorkerPool({ | ||
maxWorkers: groupMaxWorkers, | ||
@@ -66,3 +84,3 @@ workerOptions, | ||
if (defaultPoolWorkersCount > 0) { | ||
this.defaultPool = new _workerPoolJs.WorkerPool({ | ||
this.defaultPool = new _WorkerPool.WorkerPool({ | ||
maxWorkers: defaultPoolWorkersCount, | ||
@@ -69,0 +87,0 @@ workerOptions, |
@@ -7,6 +7,8 @@ "use strict"; | ||
enumerable: true, | ||
get: ()=>createFilteredStreamTransform | ||
get: function() { | ||
return createFilteredStreamTransform; | ||
} | ||
}); | ||
const _stream = require("stream"); | ||
const _stdioStreamMarkersJs = require("./stdioStreamMarkers.js"); | ||
const _stdioStreamMarkers = require("./stdioStreamMarkers.js"); | ||
function createFilteredStreamTransform() { | ||
@@ -16,7 +18,7 @@ const transform = new _stream.Transform({ | ||
let str = chunk.toString(); | ||
if (str.includes(_stdioStreamMarkersJs.START_MARKER_PREFIX)) { | ||
str = str.replace(new RegExp(_stdioStreamMarkersJs.START_MARKER_PREFIX + "[0-9a-z]{64}\n"), ""); | ||
if (str.includes(_stdioStreamMarkers.START_MARKER_PREFIX)) { | ||
str = str.replace(new RegExp(_stdioStreamMarkers.START_MARKER_PREFIX + "[0-9a-z]{64}\n"), ""); | ||
} | ||
if (str.includes(_stdioStreamMarkersJs.END_MARKER_PREFIX)) { | ||
str = str.replace(new RegExp(_stdioStreamMarkersJs.END_MARKER_PREFIX + "[0-9a-z]{64}\n"), ""); | ||
if (str.includes(_stdioStreamMarkers.END_MARKER_PREFIX)) { | ||
str = str.replace(new RegExp(_stdioStreamMarkers.END_MARKER_PREFIX + "[0-9a-z]{64}\n"), ""); | ||
} | ||
@@ -23,0 +25,0 @@ callback(null, str); |
@@ -12,8 +12,14 @@ "use strict"; | ||
_export(exports, { | ||
registerWorker: ()=>_registerWorkerJs.registerWorker, | ||
WorkerPool: ()=>_workerPoolJs.WorkerPool, | ||
AggregatedPool: ()=>_aggregatedPoolJs.AggregatedPool | ||
registerWorker: function() { | ||
return _registerWorker.registerWorker; | ||
}, | ||
WorkerPool: function() { | ||
return _WorkerPool.WorkerPool; | ||
}, | ||
AggregatedPool: function() { | ||
return _AggregatedPool.AggregatedPool; | ||
} | ||
}); | ||
const _registerWorkerJs = require("./registerWorker.js"); | ||
const _workerPoolJs = require("./WorkerPool.js"); | ||
const _aggregatedPoolJs = require("./AggregatedPool.js"); | ||
const _registerWorker = require("./registerWorker.js"); | ||
const _WorkerPool = require("./WorkerPool.js"); | ||
const _AggregatedPool = require("./AggregatedPool.js"); |
@@ -7,8 +7,10 @@ "use strict"; | ||
enumerable: true, | ||
get: ()=>registerWorker | ||
get: function() { | ||
return registerWorker; | ||
} | ||
}); | ||
const _workerThreads = require("worker_threads"); | ||
const _stdioStreamMarkersJs = require("./stdioStreamMarkers.js"); | ||
const _worker_threads = require("worker_threads"); | ||
const _stdioStreamMarkers = require("./stdioStreamMarkers.js"); | ||
function registerWorker(fn) { | ||
_workerThreads.parentPort?.on("message", async (message)=>{ | ||
_worker_threads.parentPort?.on("message", async (message)=>{ | ||
let abortController; | ||
@@ -22,3 +24,3 @@ switch(message.type){ | ||
case "check-memory-usage": | ||
return reportMemory(_workerThreads.parentPort); | ||
return reportMemory(_worker_threads.parentPort); | ||
} | ||
@@ -28,6 +30,6 @@ }); | ||
try { | ||
process.stdout.write(`${(0, _stdioStreamMarkersJs.startMarker)(workerTaskId)}\n`); | ||
process.stderr.write(`${(0, _stdioStreamMarkersJs.startMarker)(workerTaskId)}\n`); | ||
process.stdout.write(`${(0, _stdioStreamMarkers.startMarker)(workerTaskId)}\n`); | ||
process.stderr.write(`${(0, _stdioStreamMarkers.startMarker)(workerTaskId)}\n`); | ||
const results = await fn(task, abortSignal); | ||
_workerThreads.parentPort?.postMessage({ | ||
_worker_threads.parentPort?.postMessage({ | ||
type: "status", | ||
@@ -38,3 +40,3 @@ err: undefined, | ||
} catch (err) { | ||
_workerThreads.parentPort?.postMessage({ | ||
_worker_threads.parentPort?.postMessage({ | ||
type: "status", | ||
@@ -45,4 +47,4 @@ err, | ||
} finally{ | ||
process.stdout.write(`${(0, _stdioStreamMarkersJs.endMarker)(workerTaskId)}\n`); | ||
process.stderr.write(`${(0, _stdioStreamMarkersJs.endMarker)(workerTaskId)}\n`); | ||
process.stdout.write(`${(0, _stdioStreamMarkers.endMarker)(workerTaskId)}\n`); | ||
process.stderr.write(`${(0, _stdioStreamMarkers.endMarker)(workerTaskId)}\n`); | ||
} | ||
@@ -49,0 +51,0 @@ } |
@@ -12,6 +12,14 @@ "use strict"; | ||
_export(exports, { | ||
START_MARKER_PREFIX: ()=>START_MARKER_PREFIX, | ||
END_MARKER_PREFIX: ()=>END_MARKER_PREFIX, | ||
startMarker: ()=>startMarker, | ||
endMarker: ()=>endMarker | ||
START_MARKER_PREFIX: function() { | ||
return START_MARKER_PREFIX; | ||
}, | ||
END_MARKER_PREFIX: function() { | ||
return END_MARKER_PREFIX; | ||
}, | ||
startMarker: function() { | ||
return startMarker; | ||
}, | ||
endMarker: function() { | ||
return endMarker; | ||
} | ||
}); | ||
@@ -18,0 +26,0 @@ const START_MARKER_PREFIX = "## WORKER:START:"; |
@@ -7,6 +7,21 @@ "use strict"; | ||
enumerable: true, | ||
get: ()=>TaskInfo | ||
get: function() { | ||
return TaskInfo; | ||
} | ||
}); | ||
const _asyncHooks = require("async_hooks"); | ||
class TaskInfo extends _asyncHooks.AsyncResource { | ||
const _async_hooks = require("async_hooks"); | ||
function _define_property(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
class TaskInfo extends _async_hooks.AsyncResource { | ||
get id() { | ||
@@ -35,2 +50,3 @@ return this.options.id; | ||
super("WorkerPoolTaskInfo"); | ||
_define_property(this, "options", void 0); | ||
this.options = options; | ||
@@ -37,0 +53,0 @@ if (options.setup) { |
@@ -8,2 +8,3 @@ /// <reference types="node" /> | ||
import { Readable } from "stream"; | ||
import { type TransferListItem } from "worker_threads"; | ||
import type { IWorker } from "./types/WorkerQueue.js"; | ||
@@ -33,2 +34,3 @@ import type { QueueItem } from "./types/WorkerQueue.js"; | ||
checkMemoryUsage(): Promise<void>; | ||
postMessage(value: any, transferList?: readonly TransferListItem[] | undefined): void; | ||
} |
@@ -7,14 +7,16 @@ "use strict"; | ||
enumerable: true, | ||
get: ()=>ThreadWorker | ||
get: function() { | ||
return ThreadWorker; | ||
} | ||
}); | ||
const _createFilteredStreamTransformJs = require("./createFilteredStreamTransform.js"); | ||
const _createFilteredStreamTransform = require("./createFilteredStreamTransform.js"); | ||
const _readline = require("readline"); | ||
const _stdioStreamMarkersJs = require("./stdioStreamMarkers.js"); | ||
const _stdioStreamMarkers = require("./stdioStreamMarkers.js"); | ||
const _events = require("events"); | ||
const _stream = require("stream"); | ||
const _taskInfoJs = require("./TaskInfo.js"); | ||
const _workerThreads = require("worker_threads"); | ||
const _crypto = /*#__PURE__*/ _interopRequireDefault(require("crypto")); | ||
const _os = /*#__PURE__*/ _interopRequireDefault(require("os")); | ||
function _checkPrivateRedeclaration(obj, privateCollection) { | ||
const _TaskInfo = require("./TaskInfo.js"); | ||
const _worker_threads = require("worker_threads"); | ||
const _crypto = /*#__PURE__*/ _interop_require_default(require("crypto")); | ||
const _os = /*#__PURE__*/ _interop_require_default(require("os")); | ||
function _check_private_redeclaration(obj, privateCollection) { | ||
if (privateCollection.has(obj)) { | ||
@@ -24,3 +26,3 @@ throw new TypeError("Cannot initialize the same private elements twice on an object"); | ||
} | ||
function _classApplyDescriptorGet(receiver, descriptor) { | ||
function _class_apply_descriptor_get(receiver, descriptor) { | ||
if (descriptor.get) { | ||
@@ -31,3 +33,3 @@ return descriptor.get.call(receiver); | ||
} | ||
function _classApplyDescriptorSet(receiver, descriptor, value) { | ||
function _class_apply_descriptor_set(receiver, descriptor, value) { | ||
if (descriptor.set) { | ||
@@ -42,3 +44,3 @@ descriptor.set.call(receiver, value); | ||
} | ||
function _classExtractFieldDescriptor(receiver, privateMap, action) { | ||
function _class_extract_field_descriptor(receiver, privateMap, action) { | ||
if (!privateMap.has(receiver)) { | ||
@@ -49,16 +51,16 @@ throw new TypeError("attempted to " + action + " private field on non-instance"); | ||
} | ||
function _classPrivateFieldGet(receiver, privateMap) { | ||
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); | ||
return _classApplyDescriptorGet(receiver, descriptor); | ||
function _class_private_field_get(receiver, privateMap) { | ||
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get"); | ||
return _class_apply_descriptor_get(receiver, descriptor); | ||
} | ||
function _classPrivateFieldInit(obj, privateMap, value) { | ||
_checkPrivateRedeclaration(obj, privateMap); | ||
function _class_private_field_init(obj, privateMap, value) { | ||
_check_private_redeclaration(obj, privateMap); | ||
privateMap.set(obj, value); | ||
} | ||
function _classPrivateFieldSet(receiver, privateMap, value) { | ||
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); | ||
_classApplyDescriptorSet(receiver, descriptor, value); | ||
function _class_private_field_set(receiver, privateMap, value) { | ||
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set"); | ||
_class_apply_descriptor_set(receiver, descriptor, value); | ||
return value; | ||
} | ||
function _classPrivateMethodGet(receiver, privateSet, fn) { | ||
function _class_private_method_get(receiver, privateSet, fn) { | ||
if (!privateSet.has(receiver)) { | ||
@@ -69,7 +71,20 @@ throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
function _classPrivateMethodInit(obj, privateSet) { | ||
_checkPrivateRedeclaration(obj, privateSet); | ||
function _class_private_method_init(obj, privateSet) { | ||
_check_private_redeclaration(obj, privateSet); | ||
privateSet.add(obj); | ||
} | ||
function _interopRequireDefault(obj) { | ||
function _define_property(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _interop_require_default(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
@@ -86,5 +101,5 @@ default: obj | ||
const { task , resolve , reject , cleanup , setup } = work; | ||
abortSignal?.addEventListener("abort", _classPrivateMethodGet(this, _handleAbort, handleAbort)); | ||
abortSignal?.addEventListener("abort", _class_private_method_get(this, _handleAbort, handleAbort)); | ||
const id = _crypto.default.randomBytes(32).toString("hex"); | ||
_classPrivateFieldSet(this, _taskInfo, new _taskInfoJs.TaskInfo({ | ||
_class_private_field_set(this, _taskInfo, new _TaskInfo.TaskInfo({ | ||
id, | ||
@@ -101,9 +116,9 @@ weight: work.weight, | ||
// in the worker's stdout/stderr streams. | ||
_classPrivateFieldGet(this, _stdoutInfo).promise = new Promise((onResolve)=>{ | ||
_classPrivateFieldGet(this, _stdoutInfo).resolve = onResolve; | ||
_class_private_field_get(this, _stdoutInfo).promise = new Promise((onResolve)=>{ | ||
_class_private_field_get(this, _stdoutInfo).resolve = onResolve; | ||
}); | ||
_classPrivateFieldGet(this, _stderrInfo).promise = new Promise((onResolve)=>{ | ||
_classPrivateFieldGet(this, _stderrInfo).resolve = onResolve; | ||
_class_private_field_get(this, _stderrInfo).promise = new Promise((onResolve)=>{ | ||
_class_private_field_get(this, _stderrInfo).resolve = onResolve; | ||
}); | ||
_classPrivateFieldGet(this, _worker).postMessage({ | ||
_class_private_field_get(this, _worker).postMessage({ | ||
type: "start", | ||
@@ -118,20 +133,20 @@ task: { | ||
get weight() { | ||
return _classPrivateFieldGet(this, _taskInfo)?.weight ?? 1; | ||
return _class_private_field_get(this, _taskInfo)?.weight ?? 1; | ||
} | ||
get stdout() { | ||
return _classPrivateFieldGet(this, _stdoutInfo).stream; | ||
return _class_private_field_get(this, _stdoutInfo).stream; | ||
} | ||
get stderr() { | ||
return _classPrivateFieldGet(this, _stderrInfo).stream; | ||
return _class_private_field_get(this, _stderrInfo).stream; | ||
} | ||
get resourceLimits() { | ||
return _classPrivateFieldGet(this, _worker).resourceLimits; | ||
return _class_private_field_get(this, _worker).resourceLimits; | ||
} | ||
get threadId() { | ||
return _classPrivateFieldGet(this, _worker).threadId; | ||
return _class_private_field_get(this, _worker).threadId; | ||
} | ||
terminate() { | ||
_classPrivateFieldGet(this, _worker).removeAllListeners(); | ||
_classPrivateFieldGet(this, _worker).terminate(); | ||
_classPrivateFieldGet(this, _worker).unref(); | ||
_class_private_field_get(this, _worker).removeAllListeners(); | ||
_class_private_field_get(this, _worker).terminate(); | ||
_class_private_field_get(this, _worker).unref(); | ||
} | ||
@@ -141,35 +156,43 @@ restart() { | ||
this.status = "busy"; | ||
_classPrivateFieldGet(this, _worker).terminate(); | ||
_classPrivateMethodGet(this, _createNewWorker, createNewWorker).call(this); | ||
_class_private_field_get(this, _worker).terminate(); | ||
_class_private_method_get(this, _createNewWorker, createNewWorker).call(this); | ||
} | ||
async checkMemoryUsage() { | ||
_classPrivateFieldGet(this, _worker).postMessage({ | ||
_class_private_field_get(this, _worker).postMessage({ | ||
type: "check-memory-usage" | ||
}); | ||
} | ||
postMessage(value, transferList) { | ||
_class_private_field_get(this, _worker).postMessage(value, transferList); | ||
} | ||
constructor(script, options){ | ||
super(); | ||
_classPrivateMethodInit(this, _createNewWorker); | ||
_classPrivateMethodInit(this, _ready); | ||
_classPrivateMethodInit(this, _captureWorkerStdioStreams); | ||
_classPrivateMethodInit(this, _handleAbort); | ||
_classPrivateFieldInit(this, _taskInfo, { | ||
_class_private_method_init(this, _createNewWorker); | ||
_class_private_method_init(this, _ready); | ||
_class_private_method_init(this, _captureWorkerStdioStreams); | ||
_class_private_method_init(this, _handleAbort); | ||
_define_property(this, "script", void 0); | ||
_define_property(this, "options", void 0); | ||
_class_private_field_init(this, _taskInfo, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInit(this, _stdoutInfo, { | ||
_class_private_field_init(this, _stdoutInfo, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInit(this, _stderrInfo, { | ||
_class_private_field_init(this, _stderrInfo, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInit(this, _worker, { | ||
_class_private_field_init(this, _worker, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_define_property(this, "status", void 0); | ||
_define_property(this, "restarts", void 0); | ||
_define_property(this, "maxWorkerMemoryUsage", void 0); | ||
this.script = script; | ||
this.options = options; | ||
_classPrivateFieldSet(this, _stdoutInfo, { | ||
_class_private_field_set(this, _stdoutInfo, { | ||
stream: new _stream.Readable(), | ||
@@ -179,3 +202,3 @@ promise: Promise.resolve(), | ||
}); | ||
_classPrivateFieldSet(this, _stderrInfo, { | ||
_class_private_field_set(this, _stderrInfo, { | ||
stream: new _stream.Readable(), | ||
@@ -188,3 +211,3 @@ promise: Promise.resolve(), | ||
this.maxWorkerMemoryUsage = 0; | ||
_classPrivateMethodGet(this, _createNewWorker, createNewWorker).call(this); | ||
_class_private_method_get(this, _createNewWorker, createNewWorker).call(this); | ||
} | ||
@@ -195,3 +218,3 @@ } | ||
const script = this.script; | ||
const worker = new _workerThreads.Worker(script, { | ||
const worker = new _worker_threads.Worker(script, { | ||
...workerOptions, | ||
@@ -201,5 +224,5 @@ stdout: true, | ||
}); | ||
_classPrivateMethodGet(this, _captureWorkerStdioStreams, captureWorkerStdioStreams).call(this, worker); | ||
const filteredStdout = worker.stdout.pipe((0, _createFilteredStreamTransformJs.createFilteredStreamTransform)()); | ||
const filteredStderr = worker.stderr.pipe((0, _createFilteredStreamTransformJs.createFilteredStreamTransform)()); | ||
_class_private_method_get(this, _captureWorkerStdioStreams, captureWorkerStdioStreams).call(this, worker); | ||
const filteredStdout = worker.stdout.pipe((0, _createFilteredStreamTransform.createFilteredStreamTransform)()); | ||
const filteredStderr = worker.stderr.pipe((0, _createFilteredStreamTransform.createFilteredStreamTransform)()); | ||
let capturedStdoutResolve = ()=>{}; | ||
@@ -221,9 +244,9 @@ const capturedStdoutPromise = new Promise((resolve)=>{ | ||
Promise.all([ | ||
_classPrivateFieldGet(this, _stdoutInfo).promise, | ||
_classPrivateFieldGet(this, _stderrInfo).promise | ||
_class_private_field_get(this, _stdoutInfo).promise, | ||
_class_private_field_get(this, _stderrInfo).promise | ||
]).then(()=>{ | ||
const { err , results } = data; | ||
if (_classPrivateFieldGet(this, _taskInfo)) { | ||
_classPrivateFieldGet(this, _taskInfo).abortSignal?.removeEventListener("abort", _classPrivateMethodGet(this, _handleAbort, handleAbort)); | ||
_classPrivateFieldGet(this, _taskInfo).done(err, results); | ||
if (_class_private_field_get(this, _taskInfo)) { | ||
_class_private_field_get(this, _taskInfo).abortSignal?.removeEventListener("abort", _class_private_method_get(this, _handleAbort, handleAbort)); | ||
_class_private_field_get(this, _taskInfo).done(err, results); | ||
} | ||
@@ -238,3 +261,3 @@ this.checkMemoryUsage(); | ||
} else { | ||
_classPrivateMethodGet(this, _ready, ready).call(this); | ||
_class_private_method_get(this, _ready, ready).call(this); | ||
} | ||
@@ -248,9 +271,9 @@ } else { | ||
Promise.all([ | ||
_classPrivateFieldGet(this, _stdoutInfo).promise, | ||
_classPrivateFieldGet(this, _stderrInfo).promise | ||
_class_private_field_get(this, _stdoutInfo).promise, | ||
_class_private_field_get(this, _stderrInfo).promise | ||
]).then(()=>{ | ||
// In case of an uncaught exception: Call the callback that was passed to | ||
// `runTask` with the error. | ||
if (_classPrivateFieldGet(this, _taskInfo)) { | ||
_classPrivateFieldGet(this, _taskInfo).done(err, null); | ||
if (_class_private_field_get(this, _taskInfo)) { | ||
_class_private_field_get(this, _taskInfo).done(err, null); | ||
} | ||
@@ -263,4 +286,4 @@ this.emit("error", err); | ||
worker.on("error", errHandler); | ||
_classPrivateFieldSet(this, _worker, worker); | ||
_classPrivateFieldSet(this, _stdoutInfo, { | ||
_class_private_field_set(this, _worker, worker); | ||
_class_private_field_set(this, _stdoutInfo, { | ||
stream: filteredStdout, | ||
@@ -270,3 +293,3 @@ promise: capturedStdoutPromise, | ||
}); | ||
_classPrivateFieldSet(this, _stderrInfo, { | ||
_class_private_field_set(this, _stderrInfo, { | ||
stream: filteredStderr, | ||
@@ -276,9 +299,9 @@ promise: capturedStderrPromise, | ||
}); | ||
_classPrivateMethodGet(this, _ready, ready).call(this); | ||
_class_private_method_get(this, _ready, ready).call(this); | ||
} | ||
function ready() { | ||
let weight = 1; | ||
if (_classPrivateFieldGet(this, _taskInfo)) { | ||
weight = _classPrivateFieldGet(this, _taskInfo).weight; | ||
_classPrivateFieldSet(this, _taskInfo, undefined); | ||
if (_class_private_field_get(this, _taskInfo)) { | ||
weight = _class_private_field_get(this, _taskInfo).weight; | ||
_class_private_field_set(this, _taskInfo, undefined); | ||
} | ||
@@ -306,3 +329,3 @@ this.status = "free"; | ||
return (line)=>{ | ||
if (!_classPrivateFieldGet(this, _taskInfo)) { | ||
if (!_class_private_field_get(this, _taskInfo)) { | ||
// Somehow this lineHandler function is called AFTER the worker has been freed. | ||
@@ -313,10 +336,10 @@ // This can happen if there are stray setTimeout(), etc. with callbacks that outputs some messages in stdout/stderr | ||
} | ||
if (line.includes((0, _stdioStreamMarkersJs.startMarker)(_classPrivateFieldGet(this, _taskInfo).id))) { | ||
if (line.includes((0, _stdioStreamMarkers.startMarker)(_class_private_field_get(this, _taskInfo).id))) { | ||
lines = []; | ||
if (outputType === "stdout") { | ||
resolve = _classPrivateFieldGet(this, _stdoutInfo).resolve; | ||
resolve = _class_private_field_get(this, _stdoutInfo).resolve; | ||
} else { | ||
resolve = _classPrivateFieldGet(this, _stderrInfo).resolve; | ||
resolve = _class_private_field_get(this, _stderrInfo).resolve; | ||
} | ||
} else if (line.includes((0, _stdioStreamMarkersJs.endMarker)(_classPrivateFieldGet(this, _taskInfo).id))) { | ||
} else if (line.includes((0, _stdioStreamMarkers.endMarker)(_class_private_field_get(this, _taskInfo).id))) { | ||
resolve(); | ||
@@ -334,5 +357,5 @@ } else { | ||
function handleAbort() { | ||
_classPrivateFieldGet(this, _worker).postMessage({ | ||
_class_private_field_get(this, _worker).postMessage({ | ||
type: "abort" | ||
}); | ||
} |
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import type { ResourceLimits } from "worker_threads"; | ||
import type { ResourceLimits, Worker } from "worker_threads"; | ||
import type { Readable } from "stream"; | ||
@@ -30,2 +30,3 @@ import type EventEmitter from "events"; | ||
restarts: number; | ||
postMessage: Worker["postMessage"]; | ||
} |
@@ -7,8 +7,23 @@ "use strict"; | ||
enumerable: true, | ||
get: ()=>WorkerPool | ||
get: function() { | ||
return WorkerPool; | ||
} | ||
}); | ||
const _events = require("events"); | ||
const _threadWorkerJs = require("./ThreadWorker.js"); | ||
const _os = /*#__PURE__*/ _interopRequireDefault(require("os")); | ||
function _interopRequireDefault(obj) { | ||
const _ThreadWorker = require("./ThreadWorker.js"); | ||
const _os = /*#__PURE__*/ _interop_require_default(require("os")); | ||
function _define_property(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _interop_require_default(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
@@ -41,3 +56,3 @@ default: obj | ||
const { script , workerOptions } = this.options; | ||
const worker = new _threadWorkerJs.ThreadWorker(script, { | ||
const worker = new _ThreadWorker.ThreadWorker(script, { | ||
workerOptions, | ||
@@ -95,2 +110,8 @@ workerIdleMemoryLimit: this.options.workerIdleMemoryLimit | ||
super(); | ||
_define_property(this, "options", void 0); | ||
_define_property(this, "workers", void 0); | ||
_define_property(this, "freeWorkers", void 0); | ||
_define_property(this, "queue", void 0); | ||
_define_property(this, "maxWorkers", void 0); | ||
_define_property(this, "availability", void 0); | ||
this.options = options; | ||
@@ -97,0 +118,0 @@ this.workers = []; |
{ | ||
"name": "@lage-run/worker-threads-pool", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "A worker_threads pool implementation based on the official Node.js async_hooks documentation", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50520
1349