Coder Social home page Coder Social logo

async-hook's Introduction

async-hook

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.

async-hook's People

Contributors

andreasmadsen avatar omsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

async-hook's Issues

trace?

hey! do you still need trace in npm?

Errors when trying to use

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.

Re-use of project as browser polyfill?

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?

Support for Node 4 (LTS)

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 tracepackaged worked really well all the time. Better than other long-stack-trace packages. But I also like to use the LTS node version.

setInverval: unexpected behavior

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

If one of hook throws, where should it go?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.