The work done in this repository has now been integrated into the built-in
node.js async_hooks
module.
All issues regarding async_hooks
should be posted in https://github.com/nodejs/node.
Inspect the life of handle objects in node
License: MIT License
The work done in this repository has now been integrated into the built-in
node.js async_hooks
module.
All issues regarding async_hooks
should be posted in https://github.com/nodejs/node.
asyncHook.enable();
process.nextTick(function () {
throw new Error('boom');
});
No error is thrown and process exits with status 0.
hey! do you still need trace
in npm?
I'm trying to use this in an express app, node v6.x, but always get the following when bundling with webpack:
ERROR in ./~/async-hook/index.js
Module parse failed: /Users/mgreer/clones/tappestry-web/node_modules/async-hook/index.js 'return' outside of function (11:4)
You may need an appropriate loader to handle this file type.
| if (global._asyncHook.version === require('./package.json').version) {
| module.exports = global._asyncHook;
| return;
| }
| // The version don't match, this is really bad. Lets just throw
@ ./~/cls-hooked/context.js 6:18-39
@ ./src/Router.js
@ ./src/10.js
ERROR in vendor-34072c54a4422fb9817a.min.js from UglifyJs
SyntaxError: Unexpected token name «key», expected punc «;» [vendor-34072c54a4422fb9817a.min.js:7562,9]
In truth, trying to use cls-hooked, which requires this.
Hello. I've been thinking about re-creating the async_hook capabilities for the browser, in whatever kind of limited fashion. It would be interesting to me to try to create observability points for promises, and Node's async_hook seems like the only standard we have for that at the moment.
How much of this project (at 0.7.1, it's last release) do you think is still applicable, or useful, if one wanted to shim Node's async-hooks?
Do you have any thoughts surrounding asyncId's, which are extensive in the Node API but absent here? How close to implementable are those in userland?
Making the Embedder API available would be another key feature of a good browser implementation of async_hook. Do you have any thoughts on how that may be mated to the work in this project?
I just noticed that the trace
-package is broken on Node 4.4.3. The reason is probably that async-hook
now only supports Node 5.
Could you support Node 4 again? The trace
packaged worked really well all the time. Better than other long-stack-trace packages. But I also like to use the LTS node version.
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
Hi, I'm experimenting with creating a version of CLS that uses async-hook
and AsyncWrap
instead of the older AsyncListener
and it appears that it very rarely sees parentIds in the init hook.
Is this b/c of NextTickerWrap doesn't pass them? Is there an alternate way to wrap nextTick
to include it?
In the spec there is a didThrow parameter in post
hook to indicate the process continues after exception in one of the hooks.
How should I accomplish the behavior above using async-hook
?
'uncaughtException' event would allow me to handle the exception but it seems impossible to get uid
of the handle it originates.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.