File size: 819 Bytes
d739b1b
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 병렬 자식의 비동기 요청에만 node/task 귀속을 전달한다. 공유 currentNodeId는 바꾸지 않는다.
// 설명 문서: docs/specs/bong-browser-use.md (v1.12.0)
const { AsyncLocalStorage } = require('async_hooks'), contexts = new AsyncLocalStorage();
async function withNode(run, nodeId, taskId, execute) {
  const context = { run, nodeId, taskId, active: true };
  return contexts.run(context, async () => { try { return await execute(); } finally { context.active = false; } });
}
function current(run) {
  const context = contexts.getStore(); if (!context || context.run !== run) return null;
  if (!context.active) throw Object.assign(Error('Workflow node request scope has ended'), { code: 'USAGE_LEDGER_FAILED', retryable: false });
  return context;
}
module.exports = { withNode, current };