fix(request-client): make creation refresh synchronous #670
+90
−72
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.
Issue
During creation of a request we do an
await request.refresh()
right before returning the request object. This creates a call to the request node that queries the pending request's data.However the request is an EventEmitter, so
error
orconfirmed
events can be emitted while the pending request's data is being fetched. This causes consuming code to miss those events.Description of the changes
Two solutions:
Either we remove the
await request.refresh()
all together. It is not a big deal knowing that another refresh is done after the confirmation happens anyway here:requestNetwork/packages/request-client.js/src/api/request.ts
Lines 106 to 113 in 7efaec7
However it means we would remove having a "pending" state in the request.
Or we could refresh the request by injecting the data that we already have = the data that was sent to the request node = without querying the request node = in a synchronous way.
I went for the second option here.