atsushieno / mono-reactive

open source Reactive Extensions (Rx) implementation for Mono
MIT License
63 stars 16 forks source link

Throttle not working as expected #15

Open bokmadsen opened 12 years ago

bokmadsen commented 12 years ago

Throttle (in RX anyway) is supposed to only return the last value, if no new value is arriving within the timespan. If a new value arrives, the timer is reset and the value is saved. The way Throttle works now is that the first value is returned immediately (should not happen) and the timer is not reset on each arrival of a new value, ie. the value is returned when the timespan has been reached regardless of "silence" in the timespan

atsushieno commented 12 years ago

Hi, sorry for the belated reply!

I think the problem you are seeing is not exactly as what you described. For example, check out this test case: https://github.com/atsushieno/mono-reactive/blob/master/System.Reactive.Tests/System.Reactive.Linq/ObservableTest.cs#L929

This Throttle() unit test tests a call to Throttle() that takes a joint observable of Range() and Return() in each 50 milliseconds. The first 3 items in Range() are immediately evaluated, so the first item from Throttle() is 3, as the test code expects. And it does not fail.

Could you give me an example repro case so that I can investigate and pin point the actual issue?

bokmadsen commented 12 years ago

Hi

Thanks for getting back to me. I've pasted my code here http://pastebin.com/LNhdF7zN. I can't quite figure out if the test will hit the problem I have. Throttle is supposed to wait for the input to settle for the amount of time, before returning the last item. I want the service to be called when the user have stopped typing for the amount of time, instead of calling it every time. The code is more or less from the demo on the official RX site

I think there is an issue with TakeUntil also - its supposed to only return the last lookup in line 61, but it returns all lookups. I've created a random timeout, to visualize this. This is because I only want the result of the last call to the service

atsushieno commented 12 years ago

umm, thanks but I don't have working mac so I can't test your code. I'll try to extract non-MT-dependent repro, but I don't learn Apple API I'm not sure if this will work for me. Anyways let's see what happens...

atsushieno commented 12 years ago

I'm on the way to make it platform independent and eliminating random (which is going to prevent testing) ... so far I have https://gist.github.com/2693865.

atsushieno commented 12 years ago

I made some fixes so that Throttle() itself should work as expected.

I'm still having some hard time to get identical results from .NET, but it's partly because FromAsyncPattern() involves different thread which makes HistoricalScheduler (which I use for testing without consuming actual time) somewhat useless. Those fixes might be enough for you to get things working.

For TakeUntil(), I need the actual input, not just the code fragment, to reproduce the issue you are seeing.