import { BaseEvent, EventBus } from 'bubus'
const HandlerEvent = BaseEvent.extend('HandlerEvent', {})
const bus = new EventBus('SerialHandlerBus', { event_handler_concurrency: 'serial' })
const log: string[] = []
bus.on(HandlerEvent, async () => {
log.push('h1_start')
await new Promise((resolve) => setTimeout(resolve, 10))
log.push('h1_end')
})
bus.on(HandlerEvent, async () => {
log.push('h2_start')
await new Promise((resolve) => setTimeout(resolve, 10))
log.push('h2_end')
})
await bus.emit(HandlerEvent({})).done()
if (JSON.stringify(log) !== JSON.stringify(['h1_start', 'h1_end', 'h2_start', 'h2_end'])) {
throw new Error('expected serial handler execution order')
}