-
Notifications
You must be signed in to change notification settings - Fork 776
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
client/sync: return Promise.race() instead of async-promise-executor #3030
Conversation
Codecov Report
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
Updated this via UI |
Seems one client test might be failing here repeatedly, so this is eventually related to the change done and needs some investigation. |
The I worked out a solution that fixed that test, but now I am getting errors from |
|
@g11tech could you give this here a quick review? I think you are better on judging on the implications of this, I am always struggling with all-things-promises. |
Updated this via UI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great clean-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm great cleanup ❤️
similar to #3015. Rewrites
sync()
without theasync-promise-generator
api.--
The Promise returned at the end of the original code was designed to resolve either when a SYNC_SYNCHRONIZED event is emitted or when
await _fetcher.fetch()
return/throws.This was done using an async-promise-executor:
return new Promise( async (res, rej) => { ... } )
This is generally considered an anti-pattern, and violated our eslint rules, requiring an ignore comment.
--
Refactored by breaking
sync()
up into smaller methods:sync()
,syncWithFetcher()
, andresolveSync()
, and returningPromise.race([...])
instead of the async promise executor.resolveSync()
externalized tothis.resolveSync()
resolveSync()
is called as a final step to clear the fetcher and emit a debug log. This was defined inside of thesync()
function, but is now defined independently.syncWithFetcher
The internal
try/catch
block that containsawait this._fetcher.fetch()
. Now externalized to an external methodthis.syncWithFetcher()
.syncEvent
The
SYNC_SYNCHRONIZED
event that can resolvesync()
is now defined as a Promise.Return Promise
sync()
now returnsPromise.race([this.syncWithFetcher(), syncEvent])
. Resolving through whichever happens first.