import { Bus } from '@node-ts/bus-core'
import * as asyncHooks from 'async_hooks'
type CorrelationId = string
// Requests to log() would look up the executionId in this map and attach the correlationId
export const handlingContext = new Map<number, CorrelationId>()
const bus = await Bus.configure()
.withMessageReadMiddleware(async (context, next) => {
const correlationId = context.attributes.correlationId
const executionId = asyncHooks.executionAsyncId()
handlingContext.set(executionId, correlationId)
handlingContext.delete(executionId)