Dark Mode
Group by:

Provides a basic signal system. You add a Signal to whatever you want, then register callbacks to it.

You must take care to register callbacks to the signals they go with or things will not work.

A callback is just a simple function without a return value that takes a single argument, which will be whatever the callback is emitting.

DO NOT USE DIFFERENT TYPES FOR THE CALLBACK'S EMIT. It does not check if the data you provide is different than the type you are sending, so you would encounter invalid argument issues. It seems nimsuggest does notice this, so your linter ought to warn you.


Signal[T] = object
  listeners: seq[Callback[T]]
Callback[T] = proc (data: T)


proc init_signal[T](): Signal[T]
proc emit[T](self: Signal; data: T)
Emit a signal. If you need complex data types just use an object
proc add[T](self: var Signal; cb: Callback[T])
Add a listener function to this signal.
proc remove[T](self: var Signal; cb: Callback[T])
Remove a listener function from this signal.