Is there any plans to make working signals in D?

Denis Shelomovskij verylonglogin.reg at gmail.com
Mon Apr 15 05:07:30 PDT 2013


15.04.2013 13:07, Robert пишет:
>> 2. Make regular D objects on closures [4] to be able to know when
>> delegate's outer scope is destroyed (this will auto-fix both [5] and
>> [2], see Comment 2 of [2] for code example)
>
> I still don't understand what that buys us. Having a closure being an
> object would make it possible to use a weak reference, but why would you
> want that? The signal would be the only one to hold a reference to the
> lamdas context, if this reference was a weak one, then the memory would
> be claimed immediately. This is why std.signals2 holds a strong ref to
> the delegate context of a wrapping closure and a weak ref to the target
> object.

With your `std.signals2` one can't e.g. forward delegate connection like 
this:
---
/// Usage: don't pass struct pointer delegates as `del`.
void f(void delegate() del)
{
     obj.event.connect(del);
}
---
as you require explicit passing an object owning a delegate.

But it is completely unnecessary as delegate do know where it was born 
from and the fact this information isn't tracked when a closure is 
created is a language design issue. One of those fixing which is easy, 
will not break any code and will improve things a lot.

-- 
Денис В. Шеломовский
Denis V. Shelomovskij


More information about the Digitalmars-d mailing list