import { BaseEvent, EventBus } from 'abxbus'
import { z } from 'zod'
const GetConfigEvent = BaseEvent.extend('GetConfigEvent', {
event_result_type: z.record(z.string(), z.unknown()),
})
const bus = new EventBus('AppBus')
bus.on(GetConfigEvent, async () => ({ debug: true, port: 8080 }))
bus.on(GetConfigEvent, async () => ({ debug: false, timeout: 30 }))
const event = bus.emit(GetConfigEvent({}))
const values = await event.eventResultsList({ raise_if_any: false, raise_if_none: false })
// [
// {debug: true, port: 8080},
// {debug: false, timeout: 30}
// ]
const merged_config = values.reduce((acc, value) => {
if (value && typeof value === 'object' && !Array.isArray(value)) {
Object.assign(acc, value)
}
return acc
}, {})
// {debug: false, port: 8080, timeout: 30}