-
-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schedule the first element in intervals asynchronously #1186
Conversation
…lement asynchronously
There is a problem with one test - |
Thanks for PR, I will investigate |
The test runs Observable.interval(mainPeriod).take(sourceCount).endWithError(ex)
.switchMap(i => Observable.interval(1.second))
.bufferTimed(mainPeriod)
.map(_.sum) and it seems like there is a race condition - Anyway, I wouldn't consider it a bug. I'm not sure what's the best way to fix the test, maybe change createObservableEndingInError(Observable.interval(mainPeriod).take(sourceCount)), ex) to createObservableEndingInError(Observable.interval(mainPeriod).take(sourceCount).doOnComplete(Task.shift), ex) Hopefully it will negate the change and won't be flaky :D |
else | ||
task := s.scheduleOnce(initialDelay.length, initialDelay.unit, runnable) | ||
|
||
task := s.scheduleOnce(initialDelay.length, initialDelay.unit, runnable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we could do a small optimization and call
s.execute(runnable)
in case of initialDelay.length <= 0
.
It makes the following test fail:
test("issue #468 - concat is cancellable") { implicit sc =>
var items = 0
val a = Observable.now(1L)
val b = Observable.interval(1.second)
val c = (a ++ b).doOnNextF(_ => Task { items += 1 })
val d = c.take(10).subscribe()
assert(items > 0, "items > 0")
assert(sc.state.tasks.nonEmpty, "tasks.nonEmpty")
d.cancel()
assert(sc.state.tasks.isEmpty, "tasks.isEmpty")
}
But I believe it is because the test needs to be adjusted.
Before the change it processes a
then immediately the first element from b
Now it processes a
then schedules b
which is waiting to be executed so it's stuck in tasks queue.
In both cases the b
is cancelled.
I think in this case it would be OK to do s.tick(); d.cancel()
in the test
WDYT? Any thoughts @alexandru ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s.execute(runnable) in case of initialDelay.length <= 0.
I think that optimization should be done in the Scheduler
implementations, not here. We could double check if it is, but I remember the optimization is being applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, doing the optimization here as well is fine too, I personally don't mind it.
Alter ConcatCancellationSuite
That |
Another idea to fix it: |
I tried with
and run it couple of times locally, unfortunately it still fails sometimes. |
I have forgotten the problem was with the |
It seems to fix the test, thank you for the contribution! |
Awesome, thanks for your invaluable help! :) |
This fixes #1185