question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The Window boundary is not respect.

See original GitHub issue

Hi All,

I creating a library for communicate with REST endpoint. I have to buffer REST request and sent its together in the batch, but also I want to have a possibility to flush buffer.

Here is the snippet of my implementation:

PublishProcessor<Flowable<String>> flush = PublishProcessor.create();
PublishProcessor<String> restProcessor = PublishProcessor.create();

int count = 2;
int delay = 100;

TestScheduler scheduler = new TestScheduler();

Flowable<Flowable<String>> boundary = restProcessor.window(delay, TimeUnit.MILLISECONDS, scheduler, count, true)
                .mergeWith(flush);

restProcessor
                .window(boundary)
                .concatMapSingle(Flowable::toList)
                .filter(it -> !it.isEmpty())
                .subscribe(strings -> System.out.println("emit REST call >>> " + strings));

The problem is that the restProcessor first emit a value with single element instead of two.

restProcessor.offer("1");
restProcessor.offer("2");

restProcessor.offer("3");
restProcessor.offer("4");

restProcessor.offer("5");
restProcessor.offer("6");

restProcessor.offer("7");
restProcessor.offer("8");

restProcessor.offer("9");
flush.offer(Flowable.just("flush"));

restProcessor.offer("10");

System.out.println("onComplete");

restProcessor.onComplete();
flush.onComplete();

Result

emit REST call >>> [1]
emit REST call >>> [2, 3]
emit REST call >>> [4, 5]
emit REST call >>> [6, 7]
emit REST call >>> [8, 9]
onComplete
emit REST call >>> [10]

I think that the result should be:

emit REST call >>> [1, 2]
emit REST call >>> [3, 4]
emit REST call >>> [5, 6]
emit REST call >>> [7, 8]
emit REST call >>> [9]
onComplete
emit REST call >>> [10]

The Junit test for reproduce is here (Gist)

RxJava version

io.reactivex.rxjava2:rxjava:2.2.4.

Java version

java version “1.8.0_152”

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
akarnokdcommented, Dec 5, 2018

Works as intended. What happens is that the boundary fires before the main sequence gets 2, thus 2 ends up in the subsequent window. You have to swap the order of the consumers to the restProcessor via another processor:

PublishProcessor<Flowable<String>> flush = PublishProcessor.create();
PublishProcessor<String> restProcessor = PublishProcessor.create();

int count = 2;
int delay = 100;

TestScheduler scheduler = new TestScheduler();

Flowable<Flowable<String>> boundary = restProcessor.window(
        delay, TimeUnit.MILLISECONDS, scheduler, count, true)
                .mergeWith(flush);

// defer the subscription to the real boundary
PublishProcessor<Flowable<String>> tempBoundary = PublishProcessor.create();

restProcessor
                .window(tempBoundary)
                .concatMapSingle(Flowable::toList)
                .filter(it -> !it.isEmpty())
                .subscribe(strings -> System.out.println("emit REST call >>> " + strings));

// now subscribe to the actual boundary, this will make sure `restProcessor` has boundary as
// a second consumer.
boundary.subscribe(tempBoundary);

restProcessor.offer("1");
restProcessor.offer("2");

restProcessor.offer("3");
restProcessor.offer("4");

restProcessor.offer("5");
restProcessor.offer("6");

restProcessor.offer("7");
restProcessor.offer("8");

restProcessor.offer("9");
flush.offer(Flowable.just("flush"));

restProcessor.offer("10");

System.out.println("onComplete");

restProcessor.onComplete();
flush.onComplete();
0reactions
akarnokdcommented, Feb 5, 2019

Why did you add that observeOn in the first place? If you need asynchrony, move it further away from the windowing logic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Broken Windows Theory Applied to Boundaries & Self ...
You cannot negotiate with boundaries that directly impact you treating yourself with love, care, trust, and respect. They are your personal ...
Read more >
Do You Need A Boundary Or A (Behavior) Window? - LinkedIn
The Behavior Window, part of the Gordon Model, defines problem ownership and responsibility. It's as simple as that. (It's not an act of...
Read more >
The Importance Of Setting Healthy Boundaries - Forbes
Setting healthy boundaries is part of self-care and self-respect and should help form the base of your own personal leadership.
Read more >
You Have a Window to Draw Your Boundary. Do It.
It's how you build respect for yourself and take back your power. It's how your sense of self and values get solidified over...
Read more >
Flexbox child does not respect the boundaries of its parent
you can also use flex for image wrapper and you may set image in absolute position to avoid see it shrinking :
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found