-
Notifications
You must be signed in to change notification settings - Fork 111
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
RxScalaDemo: Make onBackpressureDropExample nicer #62
Comments
Moreover, this line in (0 to 2000).takeWhile(_ => !subscriber.isUnsubscribed).foreach(subscriber.onNext(_)) probably does not what it should, as the following example illustrates:
|
My mistake :(
(0 to 2000).toStream.takeWhile(_ => !subscriber.isUnsubscribed).foreach(subscriber.onNext(_))
import scala.util.control.Breaks.break
for(i <- 0 to 2000) {
if(subscriber.isUnsubscribed) break else subscriber.onNext(_)
}
var i = 0
while(i < 2000 && !subscriber.isUnsubscribed) {
subscriber.onNext(_)
i += 1
} which one is better? I think 1) is fragile (at least for me, easy to forget |
I'd prefer 3) as well. With |
We need to make emitting items in |
Due to project EOL status, this improvement will not be made. |
I had a look at the
onBackpressureDropExample
inRxScalaDemo
, and it took quite a while until I grasped it.Of the 2000 items emitted by the fast Observable, the first 1024 are printed, and the others aren't. However, I'd have expected an output similar to
That is, most numbers are dropped because the Subscriber is much slower than the producer, but some arbitrary elements get through. I then found out that
observeOn
requests 1024 items at once, and only then transmits the back pressure. So I wonder if we can make an example which does not needobserveOn
, or if there's another change to make the example more understandable, or if, at least, we could add some explanations. What do you think?The text was updated successfully, but these errors were encountered: