Merge pull request #13943 from Snuffleupagus/api-more-async
Use `async` a bit more in the API
This commit is contained in:
commit
954e1a1694
@ -463,13 +463,13 @@ function getDocument(src) {
|
|||||||
* @param {Object} source
|
* @param {Object} source
|
||||||
* @param {PDFDataRangeTransport} pdfDataRangeTransport
|
* @param {PDFDataRangeTransport} pdfDataRangeTransport
|
||||||
* @param {string} docId - Unique document ID, used in `MessageHandler`.
|
* @param {string} docId - Unique document ID, used in `MessageHandler`.
|
||||||
* @returns {Promise} A promise that is resolved when the worker ID of the
|
* @returns {Promise<string>} A promise that is resolved when the worker ID of
|
||||||
* `MessageHandler` is known.
|
* the `MessageHandler` is known.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
||||||
if (worker.destroyed) {
|
if (worker.destroyed) {
|
||||||
return Promise.reject(new Error("Worker was destroyed"));
|
throw new Error("Worker was destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdfDataRangeTransport) {
|
if (pdfDataRangeTransport) {
|
||||||
@ -479,8 +479,9 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||||||
source.contentDispositionFilename =
|
source.contentDispositionFilename =
|
||||||
pdfDataRangeTransport.contentDispositionFilename;
|
pdfDataRangeTransport.contentDispositionFilename;
|
||||||
}
|
}
|
||||||
return worker.messageHandler
|
const workerId = await worker.messageHandler.sendWithPromise(
|
||||||
.sendWithPromise("GetDocRequest", {
|
"GetDocRequest",
|
||||||
|
{
|
||||||
docId,
|
docId,
|
||||||
apiVersion:
|
apiVersion:
|
||||||
typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")
|
typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")
|
||||||
@ -508,13 +509,13 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||||||
standardFontDataUrl: source.useWorkerFetch
|
standardFontDataUrl: source.useWorkerFetch
|
||||||
? source.standardFontDataUrl
|
? source.standardFontDataUrl
|
||||||
: null,
|
: null,
|
||||||
})
|
}
|
||||||
.then(function (workerId) {
|
);
|
||||||
if (worker.destroyed) {
|
|
||||||
throw new Error("Worker was destroyed");
|
if (worker.destroyed) {
|
||||||
}
|
throw new Error("Worker was destroyed");
|
||||||
return workerId;
|
}
|
||||||
});
|
return workerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -587,19 +588,15 @@ class PDFDocumentLoadingTask {
|
|||||||
* @returns {Promise<void>} A promise that is resolved when destruction is
|
* @returns {Promise<void>} A promise that is resolved when destruction is
|
||||||
* completed.
|
* completed.
|
||||||
*/
|
*/
|
||||||
destroy() {
|
async destroy() {
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
|
await this._transport?.destroy();
|
||||||
|
|
||||||
const transportDestroyed = !this._transport
|
this._transport = null;
|
||||||
? Promise.resolve()
|
if (this._worker) {
|
||||||
: this._transport.destroy();
|
this._worker.destroy();
|
||||||
return transportDestroyed.then(() => {
|
this._worker = null;
|
||||||
this._transport = null;
|
}
|
||||||
if (this._worker) {
|
|
||||||
this._worker.destroy();
|
|
||||||
this._worker = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2898,13 +2895,9 @@ class WorkerTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPageIndex(ref) {
|
getPageIndex(ref) {
|
||||||
return this.messageHandler
|
return this.messageHandler.sendWithPromise("GetPageIndex", {
|
||||||
.sendWithPromise("GetPageIndex", {
|
ref,
|
||||||
ref,
|
});
|
||||||
})
|
|
||||||
.catch(function (reason) {
|
|
||||||
return Promise.reject(new Error(reason));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAnnotations(pageIndex, intent) {
|
getAnnotations(pageIndex, intent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user