Revert "Replace all trivial Promise.defer usages with regular Promises"
This reverts commit 44401d73
This commit is contained in:
parent
7a512f7299
commit
548e38cba9
5 changed files with 138 additions and 122 deletions
|
@ -105,22 +105,26 @@ export default async function sendBugReport(bugReportEndpoint, opts) {
|
|||
}
|
||||
|
||||
function _submitReport(endpoint, body, progressCallback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = new XMLHttpRequest();
|
||||
req.open("POST", endpoint);
|
||||
req.timeout = 5 * 60 * 1000;
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState === XMLHttpRequest.LOADING) {
|
||||
progressCallback(_t("Waiting for response from server"));
|
||||
} else if (req.readyState === XMLHttpRequest.DONE) {
|
||||
// on done
|
||||
if (req.status < 200 || req.status >= 400) {
|
||||
reject(new Error(`HTTP ${req.status}`));
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
req.send(body);
|
||||
});
|
||||
const deferred = Promise.defer();
|
||||
|
||||
const req = new XMLHttpRequest();
|
||||
req.open("POST", endpoint);
|
||||
req.timeout = 5 * 60 * 1000;
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState === XMLHttpRequest.LOADING) {
|
||||
progressCallback(_t("Waiting for response from server"));
|
||||
} else if (req.readyState === XMLHttpRequest.DONE) {
|
||||
on_done();
|
||||
}
|
||||
};
|
||||
req.send(body);
|
||||
return deferred.promise;
|
||||
|
||||
function on_done() {
|
||||
if (req.status < 200 || req.status >= 400) {
|
||||
deferred.reject(new Error(`HTTP ${req.status}`));
|
||||
return;
|
||||
}
|
||||
deferred.resolve();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue