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.
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.
Detaches a delegate from this signal.
Detaches a function from this signal.
The signal procedure. When called, each of the attached slots will be called synchronously.
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.
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.