Comparing version 0.6.0 to 0.7.0
@@ -378,2 +378,3 @@ "use strict"; | ||
__publicField(this, "onMessage"); | ||
__publicField(this, "shouldRecycle"); | ||
this.worker = worker; | ||
@@ -737,5 +738,12 @@ this.workerId = workerId; | ||
shouldRecycleWorker(taskInfo) { | ||
const isWorkerIsolated = this.options.isolateWorkers && taskInfo?.workerInfo; | ||
const isWorkersMemoryLimitReached = !this.options.isolateWorkers && this.options.maxMemoryLimitBeforeRecycle !== void 0 && (taskInfo?.workerInfo?.usedMemory || 0) > this.options.maxMemoryLimitBeforeRecycle; | ||
return Boolean(isWorkerIsolated || isWorkersMemoryLimitReached); | ||
if (taskInfo?.workerInfo?.shouldRecycle) { | ||
return true; | ||
} | ||
if (this.options.isolateWorkers && taskInfo?.workerInfo) { | ||
return true; | ||
} | ||
if (!this.options.isolateWorkers && this.options.maxMemoryLimitBeforeRecycle !== void 0 && (taskInfo?.workerInfo?.usedMemory || 0) > this.options.maxMemoryLimitBeforeRecycle) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
@@ -767,2 +775,18 @@ pendingCapacity() { | ||
} | ||
async recycleWorkers() { | ||
if (this.options.isolateWorkers) { | ||
return; | ||
} | ||
const exitEvents = []; | ||
Array.from(this.workers).filter((workerInfo) => { | ||
if (workerInfo.currentUsage() === 0) { | ||
exitEvents.push(once(workerInfo.worker, "exit")); | ||
this._removeWorker(workerInfo); | ||
} else { | ||
workerInfo.shouldRecycle = true; | ||
} | ||
}); | ||
await Promise.all(exitEvents); | ||
this._ensureMinimumWorkers(); | ||
} | ||
}; | ||
@@ -810,2 +834,5 @@ var _pool; | ||
} | ||
async recycleWorkers() { | ||
await __privateGet(this, _pool).recycleWorkers(); | ||
} | ||
get completed() { | ||
@@ -812,0 +839,0 @@ return __privateGet(this, _pool).completed; |
@@ -166,2 +166,3 @@ import { MessagePort, Worker } from 'worker_threads'; | ||
cancelPendingTasks(): void; | ||
recycleWorkers(): Promise<void>; | ||
get completed(): number; | ||
@@ -168,0 +169,0 @@ get duration(): number; |
{ | ||
"name": "tinypool", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
42772
1274