Purpose
Every Node developers know Node is non-blocking IO model and ES2017 provide the await
to allow an asynchronous, non-blocking method call to be performed in a similar way to an ordinary synchronous method call.
Howevery many guys do not care connect|read|write
timeout and so on. One day they ask that why my node application is hang :(.
The node event loop is waiting the io event happened forever without specify the timeout.
This plugin compiles await
to insert debug function to record elapsed time as the following:
=>in
{ let a = await 1;}
=>out
let foo = { var _ref = ; return { return _ref; };}; { return { var gen = fn; return { { try var info = genkeyarg; var value = infovalue; catch error ; return; if infodone ; else return Promise; } return ; }; }; } const __awaitdebug__ = __awaitdebug__;
Use
Install npm module npm install --save-dev babel-plugin-transform-await-debug
and remember to add
babel-plugin-transform-await-debug
plugin to babel config
Custom Debug Function
You can rewrite src/debug.js
then npm run build
to generate your code as the following:
origin
moduleexports = { console; const rv = await callee; console; return rv; }
custom
moduleexports = { /* * you can do anything what you want to do */ console; const rv = await callee; console; return rv; }
Contributing
To contribute to babel-plugin-transform-await-debug, clone this repo locally and commit your code on a separate branch.
PS: PR Welcome 🚀 🚀 🚀 🚀
Author
GitHub @detailyang
License
babel-plugin-transform-await-debug is licensed under the MIT license.