Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the getPdfManager function to be asynchronous #19091

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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