@mondaydotcomorg/node-execution-context
Version:
Persistent execution context allowing you to get/set the context anywhere implemented using async hooks. Can be used to create request level execution context, a stack trace that persists through async resources, or anything else you need to survive the e
23 lines (17 loc) • 680 B
JavaScript
function init(asyncId, type, triggerAsyncId) {
const parentContext = executionContextMap.get(triggerAsyncId);
if (!parentContext) return;
let traceArray;
if (parentContext.traceArray) {
traceArray = parentContext.traceArray.concat(
`asyncId ${asyncId}: ${type}, eAID: ${asyncHooks.executionAsyncId()}, tAID: ${triggerAsyncId}`
);
}
const newContext = { context: parentContext.context }; // direct use instaed of deconstruct for performance
if (traceArray) newContext.traceArray = traceArray;
executionContextMap.set(asyncId, newContext);
}
function destroy(asyncId) {
executionContextMap.delete(asyncId);
}
module.exports = { init, destroy };