A typed, in-process event emitter — the counterpart to FiveM's stringly typed AddEventHandler for things that never leave the resource.

var onDeath = new Signal<Ped>();
var stop = onDeath.add(ped -> trace('${ped.handle} died'));
onDeath.dispatch(somePed);
stop();

Listeners added or removed during a dispatch don't affect the dispatch in flight: the listener list is snapshotted first. That makes the common "unsubscribe myself from inside my own handler" pattern safe.

Constructor

new()

Variables

read onlylength:Int

How many listeners are currently attached.

Methods

add(listener:T ‑> Void):SignalUnsubscribe

Attaches listener, returning a function that detaches it again.

clear():Void

dispatch(value:T):Void

Calls every attached listener with value, in the order they were added.

once(listener:T ‑> Void):SignalUnsubscribe

Attaches listener for exactly one dispatch, then detaches it.

remove(listener:T ‑> Void):Void