EventDispatcher.dispatch

Dispatch an event

If the event variable in EventDispatcher is the same type as T calls func.

class EventDispatcher
@system
void
dispatch
(
T : Event
)
(
in void delegate
(
T
)
func
)

Parameters

T

*Event* to compare to **event**

func void delegate
(
T
)

callback function

Examples

void onEvent(in Event e)
{
    Eventdispatcher ed = new EventDispatcher(e);
    ed.dispatch!MyEvent(delegate void(MyEvent event) { event.toString().writeln; });
}
void onEvent(in Event e)
{
    Eventdispatcher ed = new EventDispatcher(e);
    ed.dispatch!MyEvent((MyEvent event) { event.toString().writeln; });
}
auto func = (MyEvent event) { event.toString.writeln; };
void onEvent(in Event e)
{
    Eventdispatcher ed = new EventDispatcher(e);
    ed.dispatch!MyEvent(func);
}
void onMyEvent(MyEvent event) { event.toString.writeln; }
void onEvent(in Event e)
{
    import std.functional : toDelegate;
    Eventdispatcher ed = new EventDispatcher(e);
    ed.dispatch!MyEvent(toDelegate(&onMyEvent));
}

Meta