mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Change the createPromiseCapability
helper function into a PromiseCapability
class
This is not only slightly more compact, but it also simplifies the handling of the `settled` getter.
This commit is contained in:
parent
f9c2a8d437
commit
317abd6d07
24 changed files with 117 additions and 122 deletions
|
@ -17,10 +17,10 @@
|
|||
const {
|
||||
AnnotationLayer,
|
||||
AnnotationMode,
|
||||
createPromiseCapability,
|
||||
getDocument,
|
||||
GlobalWorkerOptions,
|
||||
PixelsPerInch,
|
||||
PromiseCapability,
|
||||
renderTextLayer,
|
||||
shadow,
|
||||
XfaLayer,
|
||||
|
@ -922,7 +922,7 @@ class Driver {
|
|||
}
|
||||
|
||||
_send(url, message) {
|
||||
const capability = createPromiseCapability();
|
||||
const capability = new PromiseCapability();
|
||||
this.inflight.textContent = this.inFlightRequests++;
|
||||
|
||||
fetch(url, {
|
||||
|
|
|
@ -17,7 +17,6 @@ import {
|
|||
AnnotationEditorType,
|
||||
AnnotationMode,
|
||||
AnnotationType,
|
||||
createPromiseCapability,
|
||||
ImageKind,
|
||||
InvalidPDFException,
|
||||
MissingPDFException,
|
||||
|
@ -26,6 +25,7 @@ import {
|
|||
PasswordException,
|
||||
PasswordResponses,
|
||||
PermissionFlag,
|
||||
PromiseCapability,
|
||||
UnknownErrorException,
|
||||
} from "../../src/shared/util.js";
|
||||
import {
|
||||
|
@ -137,7 +137,7 @@ describe("api", function () {
|
|||
const loadingTask = getDocument(basicApiGetDocumentParams);
|
||||
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||
|
||||
const progressReportedCapability = createPromiseCapability();
|
||||
const progressReportedCapability = new PromiseCapability();
|
||||
// Attach the callback that is used to report loading progress;
|
||||
// similarly to how viewer.js works.
|
||||
loadingTask.onProgress = function (progressData) {
|
||||
|
@ -199,7 +199,7 @@ describe("api", function () {
|
|||
const loadingTask = getDocument(typedArrayPdf);
|
||||
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||
|
||||
const progressReportedCapability = createPromiseCapability();
|
||||
const progressReportedCapability = new PromiseCapability();
|
||||
loadingTask.onProgress = function (data) {
|
||||
progressReportedCapability.resolve(data);
|
||||
};
|
||||
|
@ -229,7 +229,7 @@ describe("api", function () {
|
|||
const loadingTask = getDocument(arrayBufferPdf);
|
||||
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||
|
||||
const progressReportedCapability = createPromiseCapability();
|
||||
const progressReportedCapability = new PromiseCapability();
|
||||
loadingTask.onProgress = function (data) {
|
||||
progressReportedCapability.resolve(data);
|
||||
};
|
||||
|
@ -291,8 +291,8 @@ describe("api", function () {
|
|||
const loadingTask = getDocument(buildGetDocumentParams("pr6531_1.pdf"));
|
||||
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||
|
||||
const passwordNeededCapability = createPromiseCapability();
|
||||
const passwordIncorrectCapability = createPromiseCapability();
|
||||
const passwordNeededCapability = new PromiseCapability();
|
||||
const passwordIncorrectCapability = new PromiseCapability();
|
||||
// Attach the callback that is used to request a password;
|
||||
// similarly to how the default viewer handles passwords.
|
||||
loadingTask.onPassword = function (updatePassword, reason) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
import {
|
||||
AbortException,
|
||||
createPromiseCapability,
|
||||
PromiseCapability,
|
||||
UnknownErrorException,
|
||||
} from "../../src/shared/util.js";
|
||||
import { LoopbackPort } from "../../src/display/api.js";
|
||||
|
@ -338,7 +338,7 @@ describe("message_handler", function () {
|
|||
it("should ignore any pull after close is called", async function () {
|
||||
let log = "";
|
||||
const port = new LoopbackPort();
|
||||
const capability = createPromiseCapability();
|
||||
const capability = new PromiseCapability();
|
||||
const messageHandler2 = new MessageHandler("worker", "main", port);
|
||||
messageHandler2.on("fakeHandler", (data, sink) => {
|
||||
sink.onPull = function () {
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
import {
|
||||
bytesToString,
|
||||
createPromiseCapability,
|
||||
createValidAbsoluteUrl,
|
||||
getModificationDate,
|
||||
isArrayBuffer,
|
||||
PromiseCapability,
|
||||
string32,
|
||||
stringToBytes,
|
||||
stringToPDFString,
|
||||
|
@ -212,9 +212,9 @@ describe("util", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("createPromiseCapability", function () {
|
||||
describe("PromiseCapability", function () {
|
||||
it("should resolve with correct data", async function () {
|
||||
const promiseCapability = createPromiseCapability();
|
||||
const promiseCapability = new PromiseCapability();
|
||||
expect(promiseCapability.settled).toEqual(false);
|
||||
|
||||
promiseCapability.resolve({ test: "abc" });
|
||||
|
@ -225,7 +225,7 @@ describe("util", function () {
|
|||
});
|
||||
|
||||
it("should reject with correct reason", async function () {
|
||||
const promiseCapability = createPromiseCapability();
|
||||
const promiseCapability = new PromiseCapability();
|
||||
expect(promiseCapability.settled).toEqual(false);
|
||||
|
||||
promiseCapability.reject(new Error("reason"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue