Detaches all connections from the signal.
Emits the signal.
Determines if any connections are connected to the signal.
Returns a reference to the socket of this signal.
// declare a signal Signal!int signal; { // define a connection SignalConnection conn; // establish a connection between the signal and a delegate signal.socket.connect(conn, (i) { assert(i == 42); }); // emitting the signal will call the above delegate signal.emit(42); } // once there are no copies of the connection left, it will // automatically disconnect, so the following emit will // not have an effect. signal.emit(13); // if a class connects to a member function, it must store the connection, // so that the connection life time is limited to the instance lifetime. class Test { SignalConnection conn; this() @safe nothrow { signal.socket.connect(conn, &slot); } void slot(int i) @safe nothrow { assert(i == 32); } } auto t = new Test; signal.emit(32);
This example shots the recommended convention for defining signals.
class Widget { private { Signal!bool m_visibilityChangeSignal; } @property ref SignalSocket!bool visibilityChangeSignal() { return m_visibilityChangeSignal.socket; } void setVisibility(bool v) { // ... m_visibilityChangeSignal.emit(v); } } class Layout { private { SignalConnection m_visConn; Widget m_client; } void setClient(Widget w) { m_client = w; // automatically disconnects a possible connection to a previous widget w.visibilityChangeSignal.connect(m_visConn, &onChildVisibilityChange); } void onChildVisibilityChange(bool) nothrow { // ... } } auto l = new Layout; auto w = new Widget; l.setClient(w); w.setVisibility(true);
A thread local signal-slot implementation.