dimsuz
07/26/2020, 11:06 PMgenerate
operator in the snippet below causes tons of "received X" lines be printed between "fetched a page". Documentation suggests that emitter will be asked to emit by downstream and concatMap
should ask for the next value upon completion of inner source (I guess). Any idea how can I make generate
not eager in this scenario?
Observable
.generate(
{ 0 },
BiFunction { s: Int, emitter: Emitter<Int> -> emitter.onNext(s); s + 1 }
)
.doOnNext { println("received $it") }
.concatMapSingle { page ->
Single
.just(if (page == 3) emptyList() else listOf(page))
.delay(100, TimeUnit.MILLISECONDS)
}
.doOnNext { println("fetched a page") }
.takeWhile { it.isNotEmpty() }
.blockingSubscribe()