Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const asyncHooks = require('async_hooks')
const print = require('../lib/print')
function init(id, type, triggerAsyncId, resource) {
print({ stage: 'init', id, type, triggerAsyncId })
}
const hook = asyncHooks.createHook({ init })
setTimeout(() => {}, 10)
// TODO:
// Here we don't see anything printed. Do you know why?
hook.enable()
const async_hooks = require('async_hooks');
const hook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId) { }
});
hook.enable();
function createHooks(namespace) {
function init(asyncId, type, triggerId, resource) {
if (namespace.context[triggerId]) {
namespace.context[asyncId] = namespace.context[triggerId];
}
}
function destroy(asyncId) {
delete namespace.context[asyncId];
}
const asyncHook = asyncHooks.createHook({ init, destroy });
asyncHook.enable();
}
function createHooks(nsp: Namespace): void {
function init(asyncId, type, triggerId, resource) {
if (nsp.context[triggerId]) {
nsp.context[asyncId] = nsp.context[triggerId];
}
}
function destroy(asyncId): void {
delete nsp.context[asyncId];
}
const asyncHook = asyncHooks.createHook({ init, destroy });
asyncHook.enable();
}
constructor(broker) {
this.broker = broker;
this.hook = asyncHooks.createHook({
init: this._init.bind(this),
//before: this._before.bind(this),
//after: this._after.bind(this),
destroy: this._destroy.bind(this),
promiseResolve: this._destroy.bind(this)
});
this.executionAsyncId = executionAsyncId;
this.store = new Map();
}