paul
paul

Reputation: 13471

SkipUntil does not work as expect

I´m looking the operator SkipUntil, but seems like is not working as I expecting. Here is my code

@Test
public void testSkiUitil() throws InterruptedException {
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
    Observable observable2 = Observable.just(1);
    Subscription subscription = Observable.from(numbers)
                                          .skipUntil(observable2)
                                          .subscribe(System.out::println);
    Thread.sleep(3000);
    observable2.subscribe();
    new TestSubscriber((Observer) subscription).awaitTerminalEvent(5, TimeUnit.SECONDS);

}

I was trying to prove that since observable2 does not have any subscribed, so is not emitting any item the first observable using the operator skipUntil should skip all items. But still is emitting all the 5 items.

Any idea why?.

The doc says.

   Returns an Observable that skips items emitted by the source Observable until a second Observable emits

Upvotes: 2

Views: 1187

Answers (1)

JohnWowUs
JohnWowUs

Reputation: 3083

The operator skipUntil itself subscribes to the observable in the argument. See the source code here.

Upvotes: 5

Related Questions