[android] make sure devicePushToken AsyncCondition is always resolved properly #2661
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.
Why
Fix for #2381 . It's currently possible to get in a state where the
AsyncCondition
fordevicePushToken
is resolved before the conditions inisReady
in the method to get the Expo push token are met. In this case, the promise from thegetExpoPushTokenAsync
method never gets resolved or rejected.How
Changed the
isReady
condition and the location of theAsyncCondition.notify
calls so this state is no longer possible.Also ensured that even if errors happen in the body of the
onHandleIntent
method,AsyncCondition.notify
will still be called => the promise will be rejected instead of hanging.Test Plan
Built a standalone app that logs the Expo push token immediately upon launch. Before this change, the promise would never resolve ~75% of the time on a fresh install. After the change, it has resolved 10/10 times I tested.