mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Convert the getPdfManager
function to be asynchronous
This is fairly old code, and by making the function `async` we can handle initialization errors "automatically" without the need for try-catch statements.
This commit is contained in:
parent
1f6cc85134
commit
8ec399d7e1
1 changed files with 8 additions and 20 deletions
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue