Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Operator: Window #102

benjchristensen opened this Issue · 5 comments

3 participants


That's enough issues I think. :)


Started work on window()


Thanks for getting involved @bcotton !


Trying to figure out what the behavior should be, for windows when onComplete() is never called on the observer.

This test fails, as there are "hanging" values, and I only get back the first window.

        public void testNonOverlappingWindowsNoComplete() {
            Observable<Observable<String>> subject = Observable.create(new Func1<Observer<String>, Subscription>() {
                public Subscription call(Observer<String> observer) {
                    return Subscriptions.empty();

            List<List<String>> windows = toLists(subject);

            assertEquals(2, windows.size());
            assertEquals(list("one", "two", "three"), windows.get(0));
            assertEquals(list("four", "five"), windows.get(1));

Perhaps I'm missing something about the internals of Observables and what happens at "the end".


Each window Observable you emit will need to invoke onCompleted as that will not come from the origin.

As for the origin, it is possible for it to never emit an onCompleted if it is an infinite stream, in which case the Observable would continue emitting events and windows indefinitely.

However, in your example above, since you're not trying to do an infinite stream, you need to call observer.onCompleted() after observer.onNext("five") to comply with the Observable contract.

You can see some examples here:

The contract for an Observer is that onNext can be called 0 or more times and then onError or onCompleted called once with nothing following. (Javadoc) If it's an infinite stream then onCompleted may never be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.