Closed marukami closed 8 years ago
@marukami : been a crazy 2 weeks, so slowly punching through your great work.
some thoughts:
Observable.interval
provides the "polling" functionality almost for free. onStartIncreasinglyDelayedPolling
is super cool (thanks for the suggestion) but already represented in this exponential backoff example?Observable.create
unless it is the absolute best solution.I'm pulling your PR down and making some changes, which i think should be a simpler solution to the polling problem. Please let me know what you think
@kaushikgopal no worries, it's been a bit wild for me also.
Observable.interval
i had was it does not work for the task to finish before scheduling it again. This is fine if intervals are not close together, but I need to aggressively poll in some situations.onStartIncreasinglyDelayedPolling
. Observable.interval
and have it wait for each action to finish. Looking at SchedulerWorkerTest as an example, I think it should possible with a custom scheduler.
- I think it's fine removing onStartIncreasinglyDelayedPolling.
Actually i think it would be fun to reimplement it here with repeatWhen
instead of retryWhen
. I'll update the PR.
- The main issue with Observable.interval i had was it does not work for the task to finish before scheduling it again. This is fine if intervals are not close together, but I need to aggressively poll in some situations.
Dang. You're totally right. I think we could still use a repeatWhen
to handle that. Let me give it a try
actually doesn't appear to be a problem; even if the task takes long it waits until next is executed (as per a quick implementation). merging the PR with some changes, let me know if you see any issues.
even if the task takes long it waits until next is executed
You're right. It looks like Observable.interval
does wait for the task to finish. Internally it uses an OnSubscribeTimerPeriodically and that calls schedulePeriodically
. I can't remember what I was doing that broke it in my project. Oh well, I'll just update the project and see if it breaks again.
The example looks way better now. Thanks for fixing it up.
I worked out why just using interval does not work. While Interval itself will wait for each tick. When you map an Observable over Interval it does not. The map will not wait for each task to finish. I've uploaded an example in another branch here
I'll work on fix today and upload something tonight.
Thread.sleep 02-26 06:26:18.585 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 0, WaitTime: 8sec 02-26 06:26:26.589 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 1, WaitTime: 8sec 02-26 06:26:34.589 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 2, WaitTime: 8sec 02-26 06:26:42.589 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 3, WaitTime: 8sec 02-26 06:26:46.593 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 4, WaitTime: 4sec 02-26 06:26:54.593 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 5, WaitTime: 8sec 02-26 06:27:02.593 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 6, WaitTime: 8sec 02-26 06:27:10.593 22212-22938/com.morihacky.android.rxjava I/PollingFragment$$M: Task: 7, WaitTime: 8sec
When sleeping the sequence is preserved.
If you return an Observable from the map of interval you get this. 02-26 05:22:28.529 22212-22938/com.morihacky.android.rxjava I/PollingFragment$6$$M: Task: 0, WaitTime: 4sec 02-26 05:22:32.521 22212-22938/com.morihacky.android.rxjava I/PollingFragment$6$$M: Task: 4, WaitTime: 4sec 02-26 05:22:33.521 22212-22938/com.morihacky.android.rxjava I/PollingFragment$6$$M: Task: 1, WaitTime: 8sec 02-26 05:22:33.537 22212-22938/com.morihacky.android.rxjava I/PollingFragment$6$$M: Task: 5, WaitTime: 4sec 02-26 05:22:34.521 22212-22938/com.morihacky.android.rxjava I/PollingFragment$6$$M: Task: 2, WaitTime: 8sec 02-26 05:22:35.521 22212-22938/com.morihacky.android.rxjava I/PollingFragment$6$$M: Task: 3, WaitTime: 8sec 02-26 05:22:35.541 22212-22938/com.morihacky.android.rxjava I/PollingFragment$6$$M: Task: 7, WaitTime: 4sec
Let me know if you think it's OK.