@travetto/worker
Advanced tools
Comparing version 4.0.1 to 4.0.2
{ | ||
"name": "@travetto/worker", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Process management utilities, with a focus on inter-process communication", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@travetto/base": "^4.0.1", | ||
"@travetto/base": "^4.0.2", | ||
"generic-pool": "^3.9.0" | ||
@@ -31,0 +31,0 @@ }, |
import os from 'node:os'; | ||
import timers from 'node:timers/promises'; | ||
import { Options, Pool, createPool } from 'generic-pool'; | ||
@@ -81,3 +80,3 @@ | ||
while (pendingAcquires) { | ||
await timers.setTimeout(10); | ||
await Util.nonBlockingTimeout(10); | ||
} | ||
@@ -84,0 +83,0 @@ await pool.drain(); |
@@ -1,3 +0,1 @@ | ||
import { setTimeout } from 'node:timers/promises'; | ||
import { TimeSpan, Util } from '@travetto/base'; | ||
@@ -22,3 +20,3 @@ | ||
const uncaughtWithCancel: typeof uncaught & { cancel?: () => void } = uncaught; | ||
const onError = (err: Error): void => { setTimeout(1).then(() => uncaught.reject(err)); }; | ||
const onError = (err: Error): void => { Util.queueMacroTask().then(() => uncaught.reject(err)); }; | ||
process.on('unhandledRejection', onError).on('uncaughtException', onError); | ||
@@ -25,0 +23,0 @@ const cancel = (): void => { |
@@ -1,2 +0,2 @@ | ||
import { clearTimeout } from 'node:timers'; | ||
import timers from 'node:timers/promises'; | ||
import { TimeSpan, TimeUtil, Util } from '@travetto/base'; | ||
@@ -10,3 +10,3 @@ import { ExecutionError } from './error'; | ||
#id: ReturnType<typeof setTimeout> | undefined; | ||
#timeout?: AbortController; | ||
#promise = Util.resolvablePromise(); | ||
@@ -24,6 +24,6 @@ #duration: number; | ||
cancel(): void { | ||
if (this.#id) { | ||
clearTimeout(this.#id); | ||
if (this.#timeout) { | ||
this.#promise.resolve(); | ||
this.#id = undefined; | ||
this.#timeout.abort(); | ||
this.#timeout = undefined; | ||
} | ||
@@ -36,5 +36,7 @@ } | ||
wait(): Promise<void> { | ||
if (!this.#id) { | ||
this.#id = setTimeout(() => this.#promise.reject(this), this.#duration); | ||
this.#id.unref(); | ||
if (!this.#timeout) { | ||
this.#timeout = new AbortController(); | ||
timers.setTimeout(this.#duration, undefined, { ref: false, signal: this.#timeout.signal }) | ||
.then(() => this.#promise.reject(this)) | ||
.catch(() => false); | ||
} | ||
@@ -41,0 +43,0 @@ return this.#promise; |
19588
Updated@travetto/base@^4.0.2