Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirements
Tested on JDK 17 locally. CI runs JDK 8. Not tested on Java 11 or Android. The new interface method is a Java 8
defaultmethod, which Android's D8 desugars at every API level.Related issues
Describe the solution you've provided
flushBlocking()returns once the dispatcher has handed the payload to a delivery thread, not when the delivery is done. A caller that flushes and then exits can lose the events. The only way to wait for delivery today iswaitUntilInactive(), which is package-private, has no timeout, and blocks the dispatcher thread while it waits.This adds
boolean flushBlocking(long timeoutMillis):falseif the deadline passes first or the processor is closed, andtrueotherwise.On the
EventProcessorinterface it's adefaultmethod that callsflushBlocking()and returnstrue, so existing implementations and mocks still compile.One related change:
triggerFlushnow callsnotifyAll()instead ofnotify()when it gives up a busy slot, because a caller of the new method and the dispatcher can now wait on the count at the same time. The worker's release already usednotifyAll().Tests, in
DefaultEventProcessorTest:flushBlockingWithTimeoutWaitsForDeliveryflushBlockingWithTimeoutReturnsFalseIfDeliveryDoesNotFinishInTimeflushBlockingWithTimeoutReturnsFalseIfEarlierDeliveryDoesNotFinishInTimeflushBlockingWithTimeoutSucceedsWithNothingToSendflushBlockingWithTimeoutReturnsFalseAfterClosedefaultFlushBlockingWithTimeoutCallsFlushBlockingAll 375 tests in
lib/shared/internalpass, andDefaultEventProcessorTestpassed 5 repeated runs.Describe alternatives you've considered
flushBlocking()itself to wait for delivery. That would change behavior for current callers, and with no timeout it could hang an app with no network.waitUntilInactive()public. It has no timeout and blocks the dispatcher thread while it waits.Additional context
Two paths are marked
COVERAGE:because tests can't trigger them reliably: a full inbox, and the dispatcher not reaching the FLUSH message before the deadline.