Signal!() sig; SignalConnection conn; size_t cnt = 0; void slot() { cnt++; } // disconnecting using a disconnect() call sig.socket.connect(conn, &slot); sig.emit(); assert(cnt == 1); conn.disconnect(); assert(!conn.connected); sig.emit(); assert(cnt == 1); // disconnecting by destroying/overwriting the connection object sig.socket.connect(conn, &slot); sig.emit(); assert(cnt == 2); conn = SignalConnection.init; assert(!conn.connected); sig.emit(); assert(cnt == 2); // disconnecting through the signal sig.socket.connect(conn, &slot); sig.emit(); assert(cnt == 3); sig.disconnectAll(); assert(!conn.connected); sig.emit(); assert(cnt == 3); // disconnecting by destroying the signal sig.socket.connect(conn, &slot); sig.emit(); assert(cnt == 4); destroy(sig); assert(!conn.connected); sig.emit(); assert(cnt == 4);
Represents a single connection between a signal and a slot.
This type is reference counted. When the reference count drops to zero, the connection will be detached automatically.