Skip to content

Bug with "Sample" operator in 1.2.4 #4952

Closed
@kidinov

Description

@kidinov

Library version 1.2.4.

Bug reporting inspired by that SO question.

Code sample to reproduce:

Observable<String> names = Observable
        .just("Mary", "Patricia", "Linda", "Barbara",
                "Elizabeth", "Jennifer", "Maria", "Susan",
                "Margaret", "Dorothy");
Observable<Long> absoluteDelayMillis = Observable
        .just(0.1, 0.6, 0.9, 1.1,
                3.3, 3.4, 3.5, 3.6,
                4.4, 4.8)
        .map(d -> (long) (d * 1_000));
Observable<String> delayedNames = names
        .zipWith(absoluteDelayMillis,
                (n, d) -> Observable
                        .just(n)
                        .delay(d, TimeUnit.MILLISECONDS))
        .flatMap(o -> o);
delayedNames
        .sample(1, SECONDS)
        .subscribe(System.out::println);

Output:

Linda
Barbara
Susan
Dorothy

But, as far I understand that operator, it should be:

Linda
Barbara
Susan

Because "tick" on 5000 should not happen after onComplete called.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions