Skip to content

[2.1.0] buffer(timespan, unit, count) emits duplicated items #5426

@loneid

Description

@loneid

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions