-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
Thank you for your work on this project!
There seems to be a small bug or unexpected behavior regarding the monkey patched 'setInverval',
because the events are triggered in unexpected order ('destroy' before 'post'), after 'clearInterval' has been called:
const asyncHook = require('async-hook');
asyncHook.addHooks({
init: (uid, handle, provider, parentUid, parentHandle) => {
let fn = handle ? handle.constructor ? handle.constructor.name : handle.toString() : 'null';
process._rawDebug(`init : uid: ${uid} handle: ${fn}`);
},
pre: (uid) => {
process._rawDebug(`pre : uid: ${uid}`);
},
post: (uid, didThrow) => {
process._rawDebug(`post : uid: ${uid}`);
},
destroy: (uid) => {
process._rawDebug(`destroy: uid: ${uid}`);
}
});
asyncHook.enable();
const timer1 = setInterval(() => {
process._rawDebug('in interval');
clearInterval(timer1);
asyncHook.disable();
}, 100);
gms@sirius:~/test-async-hook$ node dist/index.js
warning: you are using async-hook which is unstable.
init : uid: -1 handle: IntervalWrap
pre : uid: -1
in interval
destroy: uid: -1
post : uid: -1
gms@sirius:~/test-async-hook$
I would also have a question about promises:
asyncHook.enable();
new Promise((resolve, reject) => {
process._rawDebug('resolving promise');
resolve(42);
}).then((val) => {
process._rawDebug(`promise resolved ${val}`);
asyncHook.disable();
return val;
});
which produces the following output:
resolving promise
init : uid: -1 handle: PromiseWrap
pre : uid: -1
promise resolved 42
post : uid: -1
destroy: uid: -1
Here, the promise-executor function does not trigger any events, as opposed to the 'then' call. Is this a problem of the 'async-hook' project or is this more 'AsyncWrap' related?
Regards
Guenter
Metadata
Metadata
Assignees
Labels
No labels