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 }; return { numPages, fingerprints, htmlForXfa };
} }
function getPdfManager({ async function getPdfManager({
data, data,
password, password,
disableAutoFetch, disableAutoFetch,
@ -211,32 +211,20 @@ class WorkerMessageHandler {
password, password,
rangeChunkSize, rangeChunkSize,
}; };
const pdfManagerCapability = Promise.withResolvers();
let newPdfManager;
if (data) { if (data) {
try { pdfManagerArgs.source = data;
pdfManagerArgs.source = data;
newPdfManager = new LocalPdfManager(pdfManagerArgs); return new LocalPdfManager(pdfManagerArgs);
pdfManagerCapability.resolve(newPdfManager);
} catch (ex) {
pdfManagerCapability.reject(ex);
}
return pdfManagerCapability.promise;
} }
const pdfStream = new PDFWorkerStream(handler),
fullRequest = pdfStream.getFullReader();
let pdfStream, const pdfManagerCapability = Promise.withResolvers();
let newPdfManager,
cachedChunks = [], cachedChunks = [],
loaded = 0; loaded = 0;
try {
pdfStream = new PDFWorkerStream(handler);
} catch (ex) {
pdfManagerCapability.reject(ex);
return pdfManagerCapability.promise;
}
const fullRequest = pdfStream.getFullReader();
fullRequest.headersReady fullRequest.headersReady
.then(function () { .then(function () {
if (!fullRequest.isRangeSupported) { if (!fullRequest.isRangeSupported) {
@ -315,7 +303,7 @@ class WorkerMessageHandler {
cancelXHRs = null; cancelXHRs = null;
}); });
cancelXHRs = function (reason) { cancelXHRs = reason => {
pdfStream.cancelAllRequests(reason); pdfStream.cancelAllRequests(reason);
}; };