Skip to content

Commit

Permalink
Merge pull request mozilla#19091 from Snuffleupagus/getPdfManager-async
Browse files Browse the repository at this point in the history
Convert the `getPdfManager` function to be asynchronous
  • Loading branch information
timvandermeij authored Nov 24, 2024
2 parents 8ae5b4e + 8ec399d commit d45a61b
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class WorkerMessageHandler {
return { numPages, fingerprints, htmlForXfa };
}

function getPdfManager({
async function getPdfManager({
data,
password,
disableAutoFetch,
Expand All @@ -211,32 +211,20 @@ class WorkerMessageHandler {
password,
rangeChunkSize,
};
const pdfManagerCapability = Promise.withResolvers();
let newPdfManager;

if (data) {
try {
pdfManagerArgs.source = data;
pdfManagerArgs.source = data;

newPdfManager = new LocalPdfManager(pdfManagerArgs);
pdfManagerCapability.resolve(newPdfManager);
} catch (ex) {
pdfManagerCapability.reject(ex);
}
return pdfManagerCapability.promise;
return new LocalPdfManager(pdfManagerArgs);
}
const pdfStream = new PDFWorkerStream(handler),
fullRequest = pdfStream.getFullReader();

let pdfStream,
const pdfManagerCapability = Promise.withResolvers();
let newPdfManager,
cachedChunks = [],
loaded = 0;
try {
pdfStream = new PDFWorkerStream(handler);
} catch (ex) {
pdfManagerCapability.reject(ex);
return pdfManagerCapability.promise;
}

const fullRequest = pdfStream.getFullReader();
fullRequest.headersReady
.then(function () {
if (!fullRequest.isRangeSupported) {
Expand Down Expand Up @@ -315,7 +303,7 @@ class WorkerMessageHandler {
cancelXHRs = null;
});

cancelXHRs = function (reason) {
cancelXHRs = reason => {
pdfStream.cancelAllRequests(reason);
};

Expand Down

0 comments on commit d45a61b

Please sign in to comment.