Thank you! Works great: import tables type EventEmitter = ref object eventsMap: Table[string, seq[proc(event: string)]] proc subscribe(emitter: EventEmitter, event: string, callback: proc(event: string)) = if not emitter.eventsMap.hasKey(event): emitter.eventsMap[event] = @[] emitter.eventsMap[event].add(callback) proc emit(emitter: EventEmitter, event: string) = if not emitter.eventsMap.hasKey(event): return for callback in emitter.eventsMap[event]: callback(event) Run
- How to implement observer (publish/subscribe) pattern? Kosteg
- Re: How to implement observer (publish/subscribe) pattern? dawkot
- Re: How to implement observer (publish/subscribe) pattern? Kosteg