www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.event

reply teo <teo.ubuntu yahoo.com> writes:
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.
Mar 31 2011
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Fri, 01 Apr 2011 02:02:38 +0300, teo <teo.ubuntu yahoo.com> wrote:

   1. all observers must be disconnected from the event before destroying
 them
I think this is the only correct "solution", especially given that the "delete" keyword is going away. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Apr 01 2011
parent teo <teo.ubuntu yahoo.com> writes:
On Fri, 01 Apr 2011 11:38:14 +0300, Vladimir Panteleev wrote:

 On Fri, 01 Apr 2011 02:02:38 +0300, teo <teo.ubuntu yahoo.com> wrote:
 
   1. all observers must be disconnected from the event before
   destroying
 them
I think this is the only correct "solution", especially given that the "delete" keyword is going away.
Ok, I will remove the "WithDisposeEvent" sections. One more question: are there any copyright rules for Phobos? The std.signals is copyrighted by Digital Mars, but I am not working for it. What is the correct wording in that case? I am aware only of the license requirements - it must be boost, which is fine.
Apr 01 2011