INNER CODE UNIT · JavaScript
streamDownloadWithTimeout
mozilla/firefox-translations · extension/controller/backgroundScript.js:868
const streamDownloadWithTimeout = async response => {
const MAX_DOWNLOAD_TIME = 60000;
const reader = response.body.getReader();
const contentLength = fileSize;
let receivedLength = 0;
let chunks = [];
let doneReading = false;
let value = null;
const tDownloadStart = performance.now();
let elapsedTime = 0;
while (!doneReading) {
if (elapsedTime > MAX_DOWNLOAD_TIME) {
console.log(`Max time (${MAX_DOWNLOAD_TIME}ms) reached while downloading ${itemURL}`);
sendUpdateProgress(tabId, ["updateProgress", "timeoutDownloadingEngine"]);
return false;
}
// eslint-disable-next-line no-await-in-loop
const readResponse = await reader.read();