mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Re-factor the setupFakeWorkerGlobal
function (in src/display/api.js
), and the loadFakeWorker
function (in web/app.js
)
This patch reduces some duplication, by moving *all* fake worker loader code into the `setupFakeWorkerGlobal` function. Furthermore, the functions are simplified further by using `async`/`await` where appropriate.
This commit is contained in:
parent
a5485e1ef7
commit
8519f87efb
2 changed files with 34 additions and 53 deletions
17
web/app.js
17
web/app.js
|
@ -1523,21 +1523,16 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||
};
|
||||
}
|
||||
|
||||
function loadFakeWorker() {
|
||||
async function loadFakeWorker() {
|
||||
if (!GlobalWorkerOptions.workerSrc) {
|
||||
GlobalWorkerOptions.workerSrc = AppOptions.get('workerSrc');
|
||||
}
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof SystemJS === 'object') {
|
||||
SystemJS.import('pdfjs/core/worker').then((worker) => {
|
||||
window.pdfjsWorker = worker;
|
||||
resolve();
|
||||
}).catch(reject);
|
||||
} else {
|
||||
reject(new Error('SystemJS must be used to load fake worker.'));
|
||||
}
|
||||
});
|
||||
if (typeof SystemJS !== 'object') {
|
||||
throw new Error('SystemJS must be used to load fake worker.');
|
||||
}
|
||||
window.pdfjsWorker = await SystemJS.import('pdfjs/core/worker');
|
||||
return undefined;
|
||||
}
|
||||
return loadScript(PDFWorker.getWorkerSrc());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue