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

Inline the flushChunks helper function, used in getPdfManager on the worker-thread #18992

Merged
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
35 changes: 13 additions & 22 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ class WorkerMessageHandler {
}

let pdfStream,
cachedChunks = [];
cachedChunks = [],
loaded = 0;
try {
pdfStream = new PDFWorkerStream(handler);
} catch (ex) {
Expand Down Expand Up @@ -263,30 +264,22 @@ class WorkerMessageHandler {
cancelXHRs = null;
});

let loaded = 0;
const flushChunks = function () {
const pdfFile = arrayBuffersToBytes(cachedChunks);
if (length && pdfFile.length !== length) {
warn("reported HTTP length is different from actual");
}
// the data is array, instantiating directly from it
try {
pdfManagerArgs.source = pdfFile;

newPdfManager = new LocalPdfManager(pdfManagerArgs);
pdfManagerCapability.resolve(newPdfManager);
} catch (ex) {
pdfManagerCapability.reject(ex);
}
cachedChunks = [];
};
new Promise(function (resolve, reject) {
const readChunk = function ({ value, done }) {
try {
ensureNotTerminated();
if (done) {
if (!newPdfManager) {
flushChunks();
const pdfFile = arrayBuffersToBytes(cachedChunks);
cachedChunks = [];

if (length && pdfFile.length !== length) {
warn("reported HTTP length is different from actual");
}
pdfManagerArgs.source = pdfFile;

newPdfManager = new LocalPdfManager(pdfManagerArgs);
pdfManagerCapability.resolve(newPdfManager);
}
cancelXHRs = null;
return;
Expand Down Expand Up @@ -854,9 +847,7 @@ class WorkerMessageHandler {
} else {
clearGlobalCaches();
}
if (cancelXHRs) {
cancelXHRs(new AbortException("Worker was terminated."));
}
cancelXHRs?.(new AbortException("Worker was terminated."));

for (const task of WorkerTasks) {
waitOn.push(task.finished);
Expand Down