1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

Merge pull request #19091 from Snuffleupagus/getPdfManager-async

Convert the `getPdfManager` function to be asynchronous
This commit is contained in:
Tim van der Meij 2024-11-24 15:36:29 +01:00 committed by GitHub
commit d45a61b579
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -189,7 +189,7 @@ class WorkerMessageHandler {
return { numPages, fingerprints, htmlForXfa };
}
function getPdfManager({
async function getPdfManager({
data,
password,
disableAutoFetch,
@ -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) {
@ -315,7 +303,7 @@ class WorkerMessageHandler {
cancelXHRs = null;
});
cancelXHRs = function (reason) {
cancelXHRs = reason => {
pdfStream.cancelAllRequests(reason);
};