mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
21 lines
418 B
Nim
21 lines
418 B
Nim
discard """
|
|
output: '''true
|
|
'''
|
|
"""
|
|
|
|
import tables
|
|
|
|
type EventStore = Table[string, seq[proc ()]]
|
|
|
|
proc newEventStore(): EventStore =
|
|
initTable[string, seq[proc ()]]()
|
|
|
|
proc register(store: var EventStore, name: string, callback: proc ()) =
|
|
if not store.hasKey(name):
|
|
store[name] = @[]
|
|
store[name].add(callback)
|
|
|
|
var store = newEventStore()
|
|
store.register("test", proc () = echo "true")
|
|
store["test"][0]()
|