std.event

teo teo.ubuntu at yahoo.com
Thu Mar 31 16:02:38 PDT 2011


https://github.com/teo-/phobos/tree/std-event

Instead of changing std.signals I decided to insert a new module and call 
it std.event.

There is a problem though: The observers are notified via delegates when 
the event is fired. And if an observer is destroyed the event will be 
left with a dangling reference to that observer.

I can think of two workarounds:
  1. all observers must be disconnected from the event before destroying 
them
  2. asking the runtime via a hook to inform the event about the 
destruction of an object which has registered itself as an observer

The second workaround works only with class objects, but I cannot decide 
given a delegate whether I am dealing with a class or with something 
else. The std.signals module imposes the limitation to construct 
delegates only from classes. In contrast std.event has no such a 
limitation. I've given an example with a structure. However the problem 
with dangling references remains.

So, I would like to hear your comments about the module.


More information about the Digitalmars-d mailing list