std.signals2 proposal

Jacob Carlborg doob at me.com
Tue Nov 6 07:41:07 PST 2012


On 2012-11-06 16:32, eskimo wrote:
>
>> I've not read the code and I'm not 100% sure of the intentions of
>> std.signal but why not just call the delegate as is?
>>
>
> Signals are a way of a very loose coupling of components. This loose
> coupling is the reason why people usually expect weak reference
> semantics from signals. So people expect a signal connection to simply
> vanish when the observer object dies, instead of keeping it alive
> because it holds a reference to it.
>
> The solution at the moment is to hold a reference to the object in
> memory not seen by the gc. So it gets destroyed if no one else holds a
> reference. But to avoid calling a dead object's method the signal needs
> to be notified about this, which is currently only possible for objects.
> (so no generic delegate support)
>
> The only reason why a simple delegate is not enough, is the weak
> reference semantics. If it was not for that, a signal would just be a
> simple array of delegates.

Aha, I see, that was the small detail I had missed. Thanks for the 
explanation.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list