Skip to content

Commit

Permalink
Convert DefaultExternalServices.fallback to an asynchronous method
Browse files Browse the repository at this point in the history
This method currently accepts a callback-function, which does feel a bit old fashioned now. At the time that this code was introduced, native Promises didn't exist yet and there's a custom Promise-implementation used instead.

However, today with Promises and async/await being used *a lot* it seems reasonable to change `DefaultExternalServices.fallback` to an `async` method instead such that the callback-function can be removed.
  • Loading branch information
Snuffleupagus committed Dec 30, 2020
1 parent 6e55326 commit 11ec2b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 7 additions & 8 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class DefaultExternalServices {

static initPassiveLoading(callbacks) {}

static fallback(data, callback) {}
static async fallback(data) {}

static reportTelemetry(data) {}

Expand Down Expand Up @@ -1102,18 +1102,17 @@ const PDFViewerApplication = {
return;
}
this.fellback = true;
this.externalServices.fallback(
{
this.externalServices
.fallback({
featureId,
url: this.baseUrl,
},
function response(download) {
})
.then(download => {
if (!download) {
return;
}
PDFViewerApplication.download({ sourceEventType: "download" });
}
);
this.download({ sourceEventType: "download" });
});
},

/**
Expand Down
6 changes: 4 additions & 2 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,10 @@ class FirefoxExternalServices extends DefaultExternalServices {
FirefoxCom.requestSync("initPassiveLoading", null);
}

static fallback(data, callback) {
FirefoxCom.request("fallback", data, callback);
static async fallback(data) {
return new Promise(resolve => {
FirefoxCom.request("fallback", data, resolve);
});
}

static reportTelemetry(data) {
Expand Down

0 comments on commit 11ec2b7

Please sign in to comment.