Function template declaration mystery...

Robert M. Münch robert.muench at saphirion.com
Thu Mar 1 16:07:58 UTC 2018


On 2018-03-01 12:01:19 +0000, Steven Schveighoffer said:

>> Ok, here it is: https://pastebin.com/tKACi488
>> 
>> See lines 81-84 for how I call it. And the problem I have is that 
>> doSubscribe returns "something" I'm not sure what I can do with. But if 
>> the scope ends, my subscription seems to be deleted and hence is not 
>> called when a message is coming in (see line: 118)
>> 
> 
> Looking through the rx package, it seems that it returns a class 
> instance. That class implements the Disposable interface.

Yes, AFAIU this can be kept around for reference. Seems to be intended 
for later access to the observers.

> I'm guessing from this observation that the class instance will 
> unregister the subscription if it's destroyed, and because you aren't 
> keeping a reference to that instance, the GC comes along and destroys 
> it at some point.

That was my guess too. But it's not the case. The unary is kept, hence 
I can just ignore the return value.

What bite me here was a Windows effect. I subscribed my observer after 
the call to RegisterClass/CreateWindow. But Windows sometimes calls the 
window-procedure directly, without going through the message loop. And 
the messages I want to trigger on, are exactly ones that go directly.

So, my code was never triggered because it just wasn't there. And after 
it was there, no more messages flow in. :-/

After rearranging things a bit it's working. But anyway, learned a lot 
while digging through the code and your feedback helped too.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list