You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OperatorAny (eg used in Observable.isEmpty) does an unsubscribe after seeing that there are any items in the Observable it's subscribing to, to avoid needing to generate un-needed items.
Unfortunately it seems to be unsubscribing subscribing Observables as well, which can cause it to break.
Here is an example, this code:
object OperatorAnyIssue extends App {
def debug(message: String, value: Any): Unit = printf(s"%30s %-14s $value\n", "[" + Thread.currentThread().getName + "]", message)
def sleepThenGenerateInverse(n: Boolean)() = {
debug("Generating", !n)
Thread.sleep(800)
debug("Sending", !n)
n
}
Observable.from(1 to 5)
.doOnNext(debug("Generated", _))
.doOnUnsubscribe(debug("Unsubscribed generator", ""))
.isEmpty // to fix change this line to: .toSeq.map(_.isEmpty)
.doOnNext(debug("Is empty", _))
.flatMap(i => Observable.defer { Observable.just(sleepThenGenerateInverse(i)) }.subscribeOn(IOScheduler()))
.doOnUnsubscribe(debug("Unsubscribed", ""))
.subscribe(debug("Received", _))
Thread.sleep(10000)
}
outputs the following - the sleepThenGenerateInverse function gets cut off half way through:
OperatorAny (eg used in Observable.isEmpty) does an unsubscribe after seeing that there are any items in the Observable it's subscribing to, to avoid needing to generate un-needed items.
Unfortunately it seems to be unsubscribing subscribing Observables as well, which can cause it to break.
Here is an example, this code:
outputs the following - the sleepThenGenerateInverse function gets cut off half way through:
Changing the .isEmpty line to .toSeq.map(_.isEmpty) results in the following, which is the expected behaviour:
The text was updated successfully, but these errors were encountered: