December 2017
Intermediate to advanced
322 pages
7h 3m
English
Unlike the onBackPressureBuffer() operator, which buffers emissions until the consumer consumes, the buffer() operator will gather emissions as a batch and will emit them as a list or any other collection type.
So, let's look at this example:
fun main(args: Array<String>) {
val flowable = Flowable.range(1,111)//(1)
flowable.buffer(10)//(2)
.subscribe { println(it) }
}
On comment (1), we created a Flowable instance with the Flowable.range() method, which emits integers from 1 to 111. On comment (2), we used the buffer operator with 10 as the buffer size, so the buffer operator gathers 10 items from the Flowable and emits them as a list.
The following is the output, which satisfies the understanding:
The buffer operator ...
Read now
Unlock full access