The following code:
import io.reactivex.Observable;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
public class BufferTest {
@Test
public void testBuffer() {
Observable.range(0, 10)
.map(n -> {
Thread.sleep(100);
return n;
})
.buffer(1, TimeUnit.SECONDS, 5)
.subscribe(System.out::println);
}
}
is expected to print something like:
[0, 1, 2, 3, 4]
[5, 6, 7, 8]
[9]
but try to run it several times and you can see that sometimes it prints out:
[0, 1, 2, 3, 4]
[5, 6, 7, 8, 9]
[5, 6, 7, 8, 9]
[]
where one of the bunches is duplicated.