Skip to content

Operator: throttleWithTimeout #366

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

Conversation

benjchristensen
Copy link
Member

Another take on throttle … I believe this matches Rx.Net behavior.

This will wait until timeout value has passed without any further values before emitting the received value.

Another take on `throttle` … I believe this matches Rx.Net behavior.

This will wait until timeout value has passed without any further values before emitting the received value.
@benjchristensen
Copy link
Member Author

This example will throttle by waiting until timeout value has passed without any other onNext calls before emitting. If anything else is emitted it will throw away the previous value and restart the timer.

This will not emit anything if events keep firing shorter than the timeout.

        PublishSubject<Integer> o = PublishSubject.create();
        o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s).subscribe(observer);

        // send events with simulated time increments
        s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
        o.onNext(1); // skip
        o.onNext(2); // deliver
        s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
        o.onNext(3); // skip
        s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
        o.onNext(4); // skip
        s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
        o.onNext(5); // skip
        o.onNext(6); // deliver at 1300 after 500ms has passed since onNext(5)
        s.advanceTimeTo(1300, TimeUnit.MILLISECONDS);
        o.onNext(7); // deliver
        s.advanceTimeTo(1800, TimeUnit.MILLISECONDS);
        o.onCompleted();

Compare with #365

@benjchristensen
Copy link
Member Author

Please review this behavior and let me know if it is accurate and if the name is explanatory.

@cloudbees-pull-request-builder

RxJava-pull-requests #259 SUCCESS
This pull request looks good

@samuelgruetter
Copy link
Contributor

throttleLast and throttleWithTimeout both have the same javadoc, that's confusing...

@samuelgruetter
Copy link
Contributor

that was fast :D

@benjchristensen
Copy link
Member Author

Javadoc:

Throttles by dropping all values that are followed by newer values before the timeout value expires. The timer reset on each onNext call.
NOTE: If the timeout is set higher than the rate of traffic then this will drop all data.

@benjchristensen
Copy link
Member Author

I have submitted 3 separate pull requests with different variants of throttle. I would appreciate feedback on them:

  • is the name and javadoc descriptive?
  • does the throttling strategy make sense?

Variants are:

@samuelgruetter
Copy link
Contributor

  • throttleWithTimeout: the really interesting one, not easily implemented using other operators, corresponds to the C# version
  • throttleLast: easily obtained combining window, flatMap, and takeLast
  • throttleFirst: easily obtained combining window, flatMap, and takeFirst

Is this correct?

@benjchristensen
Copy link
Member Author

Yes.

jihoonson pushed a commit to jihoonson/RxJava that referenced this pull request Mar 6, 2020
* add Bulkhead annotation and aspect

* fixed failing tests by separating retry backends.

* extracted duplicated code to AnnotationExtractor

* add Bulkhead annotation and aspect

* fixed failing tests by separating retry backends.

* extracted duplicated code to AnnotationExtractor

* extracted duplicated code to AnnotationExtractor

* added @AutoConfigureBefore and fixed wrong parameter names.

* removed bulkhead health indicator

* added dirtiesContext

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

Successfully merging this pull request may close these issues.

3 participants