@travetto/worker 5.0.0-rc.7 → 5.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/comm/channel.ts +2 -3
- package/src/support/barrier.ts +5 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/worker",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.9",
|
|
4
4
|
"description": "Process management utilities, with a focus on inter-process communication",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"exec",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "module/worker"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@travetto/runtime": "^5.0.0-rc.
|
|
28
|
+
"@travetto/runtime": "^5.0.0-rc.9",
|
|
29
29
|
"generic-pool": "^3.9.0"
|
|
30
30
|
},
|
|
31
31
|
"travetto": {
|
package/src/comm/channel.ts
CHANGED
|
@@ -89,9 +89,8 @@ export class ProcessCommChannel<T extends NodeJS.Process | ChildProcess, V = unk
|
|
|
89
89
|
async destroy(): Promise<void> {
|
|
90
90
|
if (this.#proc) {
|
|
91
91
|
console.debug('Killing', { pid: this.#parentId, id: this.id });
|
|
92
|
-
if (this.#proc
|
|
93
|
-
|
|
94
|
-
(this.#proc as ChildProcess).kill();
|
|
92
|
+
if (!('argv' in this.#proc)) {
|
|
93
|
+
this.#proc.kill();
|
|
95
94
|
}
|
|
96
95
|
this.#proc = undefined;
|
|
97
96
|
}
|
package/src/support/barrier.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { TimeSpan, Util } from '@travetto/runtime';
|
|
|
3
3
|
import { Timeout } from './timeout';
|
|
4
4
|
|
|
5
5
|
function canCancel(o: unknown): o is { cancel(): unknown } {
|
|
6
|
-
|
|
7
|
-
return !!o && 'cancel' in (o as object);
|
|
6
|
+
return !!o && (typeof o === 'object') && 'cancel' in o && typeof o.cancel === 'function';
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -14,17 +13,16 @@ export class Barrier {
|
|
|
14
13
|
/**
|
|
15
14
|
* Listen for an unhandled event, as a promise
|
|
16
15
|
*/
|
|
17
|
-
static listenForUnhandled(): Promise<unknown> & { cancel
|
|
18
|
-
const uncaught = Util.resolvablePromise<unknown>();
|
|
16
|
+
static listenForUnhandled(): Promise<unknown> & { cancel?: () => void } {
|
|
17
|
+
const uncaught = Util.resolvablePromise<Promise<unknown> & { cancel?: () => void }>();
|
|
19
18
|
const onError = (err: Error): void => { Util.queueMacroTask().then(() => uncaught.reject(err)); };
|
|
20
19
|
process.on('unhandledRejection', onError).on('uncaughtException', onError);
|
|
21
20
|
const cancel = (): void => {
|
|
22
21
|
process.off('unhandledRejection', onError).off('unhandledException', onError);
|
|
23
|
-
uncaught.resolve(undefined); // Close the promise
|
|
22
|
+
uncaught.resolve(undefined!); // Close the promise
|
|
24
23
|
};
|
|
25
24
|
Object.defineProperty(uncaught.promise, 'cancel', { value: cancel });
|
|
26
|
-
|
|
27
|
-
return uncaught.promise as unknown as ReturnType<(typeof Barrier)['listenForUnhandled']>;
|
|
25
|
+
return uncaught.promise;
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
#support: string[] = [];
|