Skip to content

Observable#window(long, java.util.concurrent.TimeUnit, long) if reached "window-max-count", the timespan not work #6651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chxchen opened this issue Sep 12, 2019 · 6 comments · Fixed by #6652
Milestone

Comments

@chxchen
Copy link

chxchen commented Sep 12, 2019

io.reactivex.Observable#window(long, java.util.concurrent.TimeUnit, long)

Observable.create((ObservableOnSubscribe<Integer>) emitter -> {
            emitter.onNext(0);
            emitter.onNext(1);
            TimeUnit.SECONDS.sleep(1);
            emitter.onNext(2);
            TimeUnit.SECONDS.sleep(6);
            emitter.onNext(4);
            emitter.onNext(5);
        })
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .window(5,TimeUnit.SECONDS, 2)
                .flatMapSingle(Observable::toList)
                .subscribe(list -> System.out.println("list=" + list + " time: "
                      + TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - l)
                      + "s"));

Like the case of above, since 7 seconds, some empty arrays are expected,and "2" will be emited when the 5 seconds,but actually not.

list=[0, 1] time: 0s
list=[2, 4] time: 7s

There is nothing after 7 seconds, it make a confuse.
As the chart https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window6.png
it says that the timeSpan still works after winow-max-size reached.

@akarnokd
Copy link
Member

How long did you wait for "5"? There is an overload where you can specify the time window should restart upon reaching the size limit.

@chxchen
Copy link
Author

chxchen commented Sep 12, 2019

How long did you wait for "5"? There is an overload where you can specify the time window should restart upon reaching the size limit.

never the "5" be passed, because createObservable does not emit a "complete" in this case of "restart" is false by default.
if restart is true, the time window will restart, that is correct.

@akarnokd
Copy link
Member

Thanks for the details, it is a bug in the operator. I'll post fixes shortly.

@chxchen
Copy link
Author

chxchen commented Sep 12, 2019

Thanks for all of your contribution!

@akarnokd
Copy link
Member

Reopening to track 2.x

@akarnokd
Copy link
Member

Closing via #6657.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants