emit

Calls all functions in a cancelable event

  1. void emit(void delegate(Args)[] events, Args args)
  2. bool emit(bool delegate(Args)[] events, Args args)
    bool
    emit
    (
    Args...
    )
    (
    bool delegate
    (
    Args
    )
    []
    events
    ,
    Args args
    )

Examples

Event!string onStringChange;
onStringChange ~= (s) { assert(s == "Foo"); };
onStringChange.emit("Foo");
Cancelable!int onIntChange;
int changed = 0;
onIntChange ~= (i) { if(i > 5) return false; changed++; return true; };
onIntChange ~= (i) { if(i > 4) return false; changed++; return true; };
onIntChange ~= (i) { if(i > 3) return false; changed++; return true; };
assert(onIntChange.emit(2));
assert(changed == 3);

changed = 0;
assert(!onIntChange.emit(4));
assert(changed == 2);

Meta