Comparing version 0.8.0 to 0.8.1
@@ -175,3 +175,4 @@ "use strict"; | ||
import { fileURLToPath as fileURLToPath2 } from "url"; | ||
var __tinypool_worker_message__ = "true"; | ||
var __tinypool_worker_message__ = true; | ||
var SIGKILL_TIMEOUT = 1e3; | ||
var ProcessWorker = class { | ||
@@ -185,2 +186,6 @@ constructor() { | ||
__publicField(this, "channel"); | ||
__publicField(this, "waitForExit"); | ||
__publicField(this, "onUnexpectedExit", () => { | ||
this.process.emit("error", new Error("Worker exited unexpectedly")); | ||
}); | ||
} | ||
@@ -191,5 +196,12 @@ initialize(options) { | ||
this.threadId = this.process.pid; | ||
this.process.on("exit", this.onUnexpectedExit); | ||
this.waitForExit = new Promise((r) => this.process.on("exit", r)); | ||
} | ||
async terminate() { | ||
return this.process.kill(); | ||
this.process.off("exit", this.onUnexpectedExit); | ||
const sigkillTimeout = setTimeout(() => this.process.kill("SIGKILL"), SIGKILL_TIMEOUT); | ||
this.process.kill(); | ||
await this.waitForExit; | ||
this.port?.close(); | ||
clearTimeout(sigkillTimeout); | ||
} | ||
@@ -223,2 +235,5 @@ setChannel(channel) { | ||
return this.process.on(event, (data) => { | ||
if (event === "error") { | ||
return callback(data); | ||
} | ||
if (!data || !data.__tinypool_worker_message__) { | ||
@@ -225,0 +240,0 @@ return this.channel?.postMessage(data); |
{ | ||
"name": "tinypool", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"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
51485
1577