A signal is an event which contains a collection of listeners (called
slots). When a signal is called, that call will be propagated to each
attached slot in a synchronous manner. It is legal for a slot to call a
signal's attach and detach methods when it is signaled. When this occurs,
attach events will be queued and processed after the signal has propagated
to all slots, but detach events are processed immediately. This ensures
that it is safe for slots to be deleted at any time, even within a slot
routine.
Example:
class Button
{
Signal!(Button) press;
}
void wasPressed( Button b )
{
printf( "Button was pressed.\n" );
}
Button b = new Button;
b.press.attach( &wasPressed );
b.press( b );
Please note that this implementation does not use weak pointers to store
references to slots. This design was chosen because weak pointers are
inherently unsafe when combined with non-deterministic destruction, with
many of the same limitations as destructors in the same situation. It is
still possible to obtain weak-pointer behavior, but this must be done
through a proxy object instead.
- alias SlotDg = void delegate(Args);
- alias SlotFn = void function(Args);
- alias call = opCall;
- Alias to simplify chained calling.
- void opCall(Args args);
- The signal procedure. When called, each of the attached slots will be
called synchronously.
Params:
Args args |
The signal arguments. |
- void attach(SlotDg dg);
- Attaches a delegate to this signal. A delegate may be either attached
or detached, so successive calls to attach for the same delegate will
have no effect.
Params:
SlotDg dg |
The delegate to attach. |
- void attach(SlotFn fn);
- Attaches a function to this signal. A function may be either attached
or detached, so successive calls to attach for the same function will
have no effect.
Params:
SlotFn fn |
The function to attach. |
- void detach(SlotDg dg);
- Detaches a delegate from this signal.
Params:
SlotDg dg |
The delegate to detach. |
- void detach(SlotFn fn);
- Detaches a function from this signal.
Params:
SlotFn fn |
The function to detach. |