-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync_hooks_api_test.js
41 lines (32 loc) · 1.09 KB
/
async_hooks_api_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const async_hooks = require('async_hooks');
const {print, print_init} = require('./output_print')
const asyncHook = async_hooks.createHook({
// called during object construction
init: function (asyncId, type, triggerAsyncId, resource) {
print_init(asyncId, type, triggerAsyncId, resource)
},
// called just before the resource's callback is called
before: function (asyncId) {
print(asyncId, 'before');
},
// called just after the resource's callback has finished
after: function (asyncId) {
print(asyncId, 'after');
},
// called when an AsyncWrap instance is destroyed
destroy: function (asyncId) {
print(asyncId, 'destroy');
},
// called only for promise resources, when the `resolve`
// function passed to the `Promise` constructor is invoked
promiseResolve: function (asyncId) {
print(asyncId, 'promiseResolve');
}
})
// starts listening for async events
asyncHook.enable()
// stops listening for new async events
// asyncHook.disable()
setTimeout(function(){
console.log("Hello");
}, 2000);