[Issue 9347] new std.signals2 implementation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 28 07:48:55 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9347



--- Comment #4 from jfanatiker at gmx.at 2013-02-28 07:48:50 PST ---
(In reply to comment #3)
> (In reply to comment #2)
> > The new implementation supports wrapping delegates, this is fact was a very
> > important feature for me.
> 
> But it doesn't do it correctly as it can't because of absence of stuff for
> controlling/watching delegate lifetime in D. See bug 9603 comment 2 for a test
> case.
It does, because it holds a strong ref to the delegate context, but a weak ref
to the target object.

The following: 
  obj.actionDone.connect(i => watch(i));

would become:
  obj.actionDone.connect!Observer(this, (o, i) => o.watch(i));

with the new implementation. Might not be as pretty, but is the only way I
could think of to make wrapper delegates work properly. This also enables the
signal to provide the strongConnect() methods which allows connecting to non
object targets, but with strong ref semantics.

The signal needs to have a strong ref to the delegate's context, but also needs
to have a weak ref to the target object. In addition the delegate's context can
not contain a reference to the target object, because this would simply destroy
the weak ref semantics. Decoupling the two and passing the object to the
delegate via a parameter, seems to be the only way to solve this issue. and at
least in my opinion not an entirely bad one.



> 
> Also new implementation doesn't handle threading issue 9606.

Thanks for pointing this out, I will fix it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list