A module for importless communication between modules. A signal is a set of callbacks. You can use signals directly in your own structs if you want them to be instance specific, of you can use global signals which are adressed by a string name.

type Callback

type Callback* = fn(args: []any)

args is a list of arguments passed to the emit method.

type Id

type Id* = uint

type Signal

type Signal* = map[Id]Callback

fn mk

fn mk*(): Signal {

Signal constructor

fn Signal.register

fn (this: ^Signal) register*(callback: Callback): Id {

Registers a callback to a signal and returns the callback id.

fn Signal.remove

fn (this: ^Signal) remove*(id: Id) {

Removes a callback by id.

fn Signal.emit

fn (this: ^Signal) emit*(args: ..any) {

Emits a signal.

fn Signal.clear

fn (this: ^Signal) clear*() {

Removes all signal handlers.

fn register

fn register*(name: str, callback: Callback): Id {

Registers a callback to a global signal. There is no need to explicitly create global signals. Returns id of the added callback

fn remove

fn remove*(name: str, id: Id) {

Removes a callback from a global signal by id.

fn remove

fn clear*(name: str) {

Removes all signal handlers from a global signal.

fn emit

fn emit*(name: str, args: ..any): std::Err {

Calls all callbacks associated with the passed global signal name.