Skip to content

Commit 9b6ca4c

Browse files
committed
Hooks suspend adjusted.
ZLIB ignore.
1 parent 7cf1697 commit 9b6ca4c

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/hooks/constants.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
* We can skip those types assuming the execution context won't be used for process types.
55
* @type {Set<String>}
66
*/
7-
exports.EXCLUDED_ASYNC_TYPES = new Set(['DNSCHANNEL', 'TLSWRAP', 'TCPWRAP', 'HTTPPARSER']);
7+
exports.EXCLUDED_ASYNC_TYPES = new Set([
8+
'DNSCHANNEL',
9+
'TLSWRAP',
10+
'TCPWRAP',
11+
'HTTPPARSER',
12+
'ZLIB'
13+
]);

src/hooks/index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ const getContextRef = (parentContext, triggerAsyncId) => (
1111
);
1212

1313
/**
14-
* Suspends map entry removal using next tick queue
15-
* @param {ExecutionContextMap} map - The execution context map
16-
* @param {Number} id - The async id to remove
14+
* Suspends a given function execution over process next tick.
15+
* @param {Function} fn - The function to trigger upon next tick.
16+
* @param {...any} args - The function arguments to trigger with.
17+
* @return {any}
1718
*/
18-
const suspendedDelete = (map, id) => process.nextTick(
19-
() => map.delete(id)
20-
);
19+
const suspend = (fn, ...args) => process.nextTick(() => fn(...args));
2120

2221
/**
2322
* The "async_hooks" init hook callback, used to initialize sub process of the main context
@@ -59,7 +58,7 @@ const onChildProcessDestroy = (executionContextMap, asyncId, ref) => {
5958

6059
// Parent context will be released upon last child removal
6160
if (!children.length) {
62-
suspendedDelete(executionContextMap, ref);
61+
executionContextMap.delete(ref)
6362

6463
return;
6564
}
@@ -85,14 +84,14 @@ const destroy = (executionContextMap) => (asyncId)=> {
8584

8685
// Child context's will unregister themselves from root context
8786
if (!isUndefined(ref)) {
88-
onChildProcessDestroy(
87+
suspend(
88+
onChildProcessDestroy,
8989
executionContextMap,
9090
asyncId,
91-
ref,
91+
ref
9292
);
9393
}
94-
95-
suspendedDelete(executionContextMap, asyncId);
94+
executionContextMap.delete(asyncId);
9695
};
9796

9897

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const createExecutionContext = () => {
4141
* @returns void
4242
*/
4343
create: (initialContext = {}) => {
44+
console.log('Creating execution context : ', executionContextMap);
4445
const asyncId = asyncHooks.executionAsyncId();
4546

4647
// Creation is allowed once per execution context

0 commit comments

Comments
 (0)