digitalmars.D - Example for creating multiple signals?
- Gary Willoughby (5/5) May 23 2013 I'm just looking at the signals example here:
- Juan Manuel Cabo (23/28) May 23 2013 class A {
- Gary Willoughby (1/1) May 23 2013 Thanks.
I'm just looking at the signals example here: "Different signals can be added to a class by naming the mixins.". Has anyone got an example of this please? I'd like to have a class raise different signals if possible.
May 23 2013
On Thursday, 23 May 2013 at 15:22:06 UTC, Gary Willoughby wrote:I'm just looking at the signals example here: "Different signals can be added to a class by naming the mixins.". Has anyone got an example of this please? I'd like to have a class raise different signals if possible.class A { mixin Signal!() onChanged; mixin Signal!(int, string) onErrorMsg; ... } class B { private void a_ErrorMsg(int code, string msg) { writeln("Error code: ", code, ": ", msg); } void attachToA(A a) { a.onErrorMsg.connect(&a_ErrorMsg); } void detachFromA(A a) { a.onErrorMsg.disconnect(&a_ErrorMsg); } } It works perfectly. BUT, keep in mind that a signal connection doesn't keep your class alive if the GC wants to take it (if the GC collects your class, it is disconnected). This means that if you want to keep your listener classes around, they must be referenced somewhere. --jm
May 23 2013