Comparing version 0.5.0 to 0.6.0
@@ -18,3 +18,3 @@ "use strict"; | ||
markMovable | ||
} from "./chunk-QYFJIXNO.js"; | ||
} from "./chunk-2H7BPY54.js"; | ||
@@ -377,2 +377,3 @@ // src/index.ts | ||
__publicField(this, "lastSeenResponseCount", 0); | ||
__publicField(this, "usedMemory"); | ||
__publicField(this, "onMessage"); | ||
@@ -425,2 +426,3 @@ this.worker = worker; | ||
_handleResponse(message) { | ||
this.usedMemory = message.usedMemory; | ||
this.onMessage(message); | ||
@@ -551,4 +553,5 @@ if (this.taskInfos.size === 0) { | ||
workerInfo.taskInfos.delete(taskId); | ||
if (!this.options.isolateWorkers) | ||
if (!this.shouldRecycleWorker(taskInfo)) { | ||
pool.workers.maybeAvailable(workerInfo); | ||
} | ||
if (taskInfo === void 0) { | ||
@@ -676,4 +679,4 @@ const err = new Error(`Unexpected message from Worker: ${inspect(message2)}`); | ||
} | ||
if (this.options.isolateWorkers && taskInfo.workerInfo) { | ||
this._removeWorker(taskInfo.workerInfo).then(() => this._ensureEnoughWorkersForTaskQueue()).then(() => resolve2(result)).catch(reject); | ||
if (this.shouldRecycleWorker(taskInfo)) { | ||
this._removeWorker(taskInfo.workerInfo).then(() => this._ensureMinimumWorkers()).then(() => this._ensureEnoughWorkersForTaskQueue()).then(() => resolve2(result)).catch(reject); | ||
} else { | ||
@@ -737,2 +740,7 @@ resolve2(result); | ||
} | ||
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); | ||
} | ||
pendingCapacity() { | ||
@@ -739,0 +747,0 @@ return this.workers.pendingItems.size * this.options.concurrentTasksPerWorker; |
@@ -8,3 +8,3 @@ "use strict"; | ||
kValue | ||
} from "./chunk-QYFJIXNO.js"; | ||
} from "./chunk-2H7BPY54.js"; | ||
@@ -118,3 +118,4 @@ // src/worker.ts | ||
result, | ||
error: null | ||
error: null, | ||
usedMemory: process.memoryUsage().heapUsed | ||
}; | ||
@@ -131,3 +132,4 @@ if (stdout()?.writableLength > 0) { | ||
result: null, | ||
error | ||
error, | ||
usedMemory: process.memoryUsage().heapUsed | ||
}; | ||
@@ -134,0 +136,0 @@ } |
@@ -52,2 +52,3 @@ import { MessagePort, Worker } from 'worker_threads'; | ||
error: unknown | null; | ||
usedMemory: number; | ||
} | ||
@@ -127,2 +128,3 @@ interface TinypoolPrivateData { | ||
resourceLimits?: ResourceLimits; | ||
maxMemoryLimitBeforeRecycle?: number; | ||
argv?: string[]; | ||
@@ -129,0 +131,0 @@ execArgv?: string[]; |
{ | ||
"name": "tinypool", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features", | ||
@@ -12,2 +12,3 @@ "type": "module", | ||
], | ||
"packageManager": "pnpm@8.4.0", | ||
"repository": { | ||
@@ -14,0 +15,0 @@ "type": "git", |
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
42131
1246