Skip to content
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

fix(request-client): make creation refresh synchronous #670

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

alexandre-abrioux
Copy link
Member

@alexandre-abrioux alexandre-abrioux commented Nov 5, 2021

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 or confirmed 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:

  1. 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:

    originalEmitter
    .on('confirmed', async () => {
    try {
    this.emitter.emit('confirmed', await this.refresh());
    } catch (error) {
    originalEmitter.emit('error', error);
    }
    })

    However it means we would remove having a "pending" state in the request.

  2. 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.

@alexandre-abrioux alexandre-abrioux changed the title fix(request-client): do not refresh right at creation fix(request-client): make creation refresh synchronous Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant