This repository was archived by the owner on Dec 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
3. Promisify subscribe/unsubscribe methods #162
Merged
Merged
Conversation
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
2146b5f to
b294a03
Compare
088d24f to
ddabc0b
Compare
d009473 to
78b52a7
Compare
236eb73 to
abea2d3
Compare
78b52a7 to
2615d55
Compare
This was referenced Sep 17, 2020
Merged
2615d55 to
d73804d
Compare
harbu
approved these changes
Sep 23, 2020
| return Promise.resolve() | ||
| } | ||
|
|
||
| return Promise.all([ |
Contributor
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.
Out of curiosity, how does this work if we are in the middle of awaiting method subscribe above?
await Promise.all([
sub.waitForSubscribed(),
this._resendAndSubscribe(sub),
])| this.once('subscribed', onSubscribed) | ||
| this.once('unsubscribed', onUnsubscribed) | ||
| this.once('error', reject) | ||
| }).then(() => this).finally(() => { |
Contributor
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.
What is this .then(() => this) needed for?
* Refactor & co-locate publish code. * Avoid using expensive ethers.Wallet.createRandom() calls in test. e.g. 1000x calls with ethers: 14s, randomBytes: 3.5ms. * Ensure messageCreationUtil is cleaned up after test. * Fix non-functional MessageCreationUtil test. * Swap out receptacle for more flexible mem/p-memoize/quick-lru. * Convert LoginEndpoints test to async/await. * Remove calls to ensureConnected/ensureDisconnected in test. * 5. Message Sequencing – Guarantee sequence follows publish order & Prevent backdated messages silently breaking future publishes (#166) * Improve authFetch logging. * Update message sequencer to strictly enforce message order. * Queue publishes per-stream otherwise can skip forward then back even when messages published in correct sequence. * Add partial solution to broken backdated messages, at least doesn't break regular sequential publishes. * Tidy up, add some comments. * Move publish queue fn into utils.
Closed
Merged
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Changes
subscribe/unsubscribeto resolve when thesubscribed/unsubscribedevents fire respectively.Simplifies consumer API significantly:
After
Before
I've got something similar as a WIP for resends.
Also should make the error handling story a bit clearer, since subscribe/unsubscribe could throw synchronously or maybe emit an error event.
e.g. to catch all possible errors with the existing streamr-client, you basically have to do something like the below,
And it gets even more hairy if you want to robustly detect which call was in progress when the error was thrown/emitted:
With these new changes, the above pattern is equivalent to:
Also related to error handling, this should probably be updated to leverage the new
requestIdproperty so it can more accurately detect & reject errors, currently it always rejects if it sees any error event event on the subscription during a subscribe/unsubscribe, meaning it's not impossible for an unrelated error to cause rejection.