Signal

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.

Members

Aliases

SlotDg
alias SlotDg = void delegate(Args)
Undocumented in source.
SlotFn
alias SlotFn = void function(Args)
Undocumented in source.
call
alias call = opCall
Undocumented in source.

Functions

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.

attach
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.

detach
void detach(SlotDg dg)

Detaches a delegate from this signal.

detach
void detach(SlotFn fn)

Detaches a function from this signal.

opCall
void opCall(Args args)

The signal procedure. When called, each of the attached slots will be called synchronously.

Examples

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.

Meta