Skip to content
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

Add Publisher.timeoutTerminal(Duration) operator #1445

Merged
merged 8 commits into from
Mar 23, 2021

Conversation

bondolo
Copy link
Contributor

@bondolo bondolo commented Mar 17, 2021

Motivation:
The existing Publisher.timeout(Duration) operator restarts the timer for each received item and will only timeout if no items are emitted during the timeout duration. In some cases the total time for all items to be emitted is of more interest. An operator to timeout based on the entire elapsed time since subscribe is needed.

Modifications:
Add a new Publisher operator, timeoutTerminal(Duration), that terminates the Publisher with a TimeoutException if the Publisher does not terminate before the specified time duration.

Result:
A new timeout option is available.

@bondolo bondolo self-assigned this Mar 17, 2021
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions and a couple questions to discuss. Otherwise, LGTM

@bondolo bondolo marked this pull request as draft March 18, 2021 17:24
@bondolo bondolo force-pushed the timeout-publisher branch 3 times, most recently from d2c2c7f to 39d1d49 Compare March 18, 2021 18:54
@bondolo bondolo changed the title Add Publisher.withTimeout(Duration) operator Add Publisher.timeoutTerminal(Duration) operator Mar 18, 2021
@bondolo bondolo marked this pull request as ready for review March 18, 2021 22:50
@bondolo bondolo requested a review from idelpivnitskiy March 18, 2021 22:54
bondolo added 6 commits March 19, 2021 11:48
Motivation:
The existing Publisher.idleTimeout(Duration) operator resets the timer
for each received item. In some cases the entire operation must be
completed with a specific amount of time.

Modifications:
Add a new Publisher operator, withTimeout(Duration, that terminates the
Publisher with a TimeoutException if it fails to otherwise terminate
before a specified time duration.

Result:
A new timeout option is available.
@bondolo bondolo force-pushed the timeout-publisher branch from 74ad853 to 0e41826 Compare March 19, 2021 18:48
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add PublisherTimeoutTerminalTckTest, similar to PublisherTimeoutTckTest.

@bondolo bondolo requested a review from Scottmitch March 22, 2021 15:53
@bondolo bondolo merged commit c63d265 into apple:main Mar 23, 2021
@bondolo bondolo deleted the timeout-publisher branch March 23, 2021 18:11
* @param duration The duration to convert
* @return The converted nanoseconds value.
*/
private long toNanos(Duration duration) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: time utility state/methods can be static and likely moved into another class (publisher has many methods so we try to keep it focused on operators).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I made this change because I notice the Java 11 has it built-in and looking at the implementation realized that overflow handling was needed.

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