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

Promisify xhrSetup #5290

Merged
merged 6 commits into from Mar 22, 2023
Merged

Conversation

fegauthier
Copy link
Contributor

This PR will...

Promisify the xhrSetup. It's useful when we need to wait that xhrSetup is completed before continuing the process.

Why is this Pull Request needed?

I need to await xhrSetup. I think it could help some others.

Are there any points in the code the reviewer needs to double check?

Resolves issues:

No issue

Checklist

  • [ X] changes have been done against master branch, and PR does not conflict
  • [ X] new unit / functional tests have been added (whenever applicable)
  • [ X] API or design changes are documented in API.md

@robwalch robwalch added this to the 1.4.0 milestone Mar 14, 2023
Comment on lines +91 to +99
.then(() => {
return xhrSetup(xhr, context.url);
})
.catch((error) => {
xhr.open('GET', context.url, true);
xhrSetup(xhr, context.url);
}
}
if (!xhr.readyState) {
xhr.open('GET', context.url, true);
}
return xhrSetup(xhr, context.url);
})
.then(() => {
this.openAndSendXhr(xhr, context, config);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With async code we should check if abortInternal has been called before continuing. Do we need an this.stats.aborted check at the start of each async callback?

Something like:

        .then(() => {
          if (this.stats.aborted) return;
          return xhrSetup(xhr, context.url);
        .then(() => {
          if (this.stats.aborted) return;
          this.openAndSendXhr(xhr, context, config);

Otherwise if a loader is initialized and is immediately followed by a call to abort, with xhrSetup, the request would still be made.

@robwalch robwalch changed the base branch from master to feature/async-xhr-setup March 22, 2023 00:02
@robwalch robwalch merged commit c4c05fe into video-dev:feature/async-xhr-setup Mar 22, 2023
@robwalch
Copy link
Collaborator

Merged into master with

  • 92abd5b
    • Update config.xhrSetup type definitions API documentation
    • Exit async xhrSetup if aborted early

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.

None yet

2 participants