-
-
Save Jeff-Lewis/f9ebdcde9d03d23f7a8a1d273e661c2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const async_hooks = require('async_hooks'); | |
let indent = 0; | |
async_hooks.createHook({ | |
init(asyncId, type, triggerAsyncId) { | |
const eid = async_hooks.executionAsyncId(); | |
const indentStr = ' '.repeat(indent); | |
fs.writeSync( | |
1, | |
`${indentStr}${type}(${asyncId}):` + | |
` trigger: ${triggerAsyncId} execution: ${eid}\n`); | |
}, | |
before(asyncId) { | |
const indentStr = ' '.repeat(indent); | |
fs.writeSync(1, `${indentStr}before: ${asyncId}\n`); | |
indent += 2; | |
}, | |
after(asyncId) { | |
indent -= 2; | |
const indentStr = ' '.repeat(indent); | |
fs.writeSync(1, `${indentStr}after: ${asyncId}\n`); | |
}, | |
destroy(asyncId) { | |
const indentStr = ' '.repeat(indent); | |
fs.writeSync(1, `${indentStr}destroy: ${asyncId}\n`); | |
}, | |
promiseResolve(asyncId) { | |
const indentStr = ' '.repeat(indent); | |
fs.writeSync(1, `${indentStr}promiseResolve: ${asyncId}\n`); | |
}, | |
}).enable(); | |
var makePromise = timeout => { | |
return new Promise(done => { | |
setTimeout(() => { | |
console.log('done'); | |
done(); | |
}, timeout); | |
}); | |
}; | |
makePromise(3000).then(() => { | |
fs.writeFile('bar.txt', 'baz', { encoding: 'utf8' }, (e) => { | |
if(e) { | |
console.log(e); | |
} | |
else { | |
console.log('finished'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment