1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #17967 from Snuffleupagus/eventBus-signal

Add `signal`-support in the `EventBus`, and utilize it in the viewer (PR 17964 follow-up)
This commit is contained in:
Tim van der Meij 2024-04-23 15:55:59 +02:00 committed by GitHub
commit bda98b91cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 246 additions and 223 deletions

View file

@ -143,6 +143,60 @@ describe("event_utils", function () {
expect(onceCount).toEqual(1);
});
it("dispatch event to handlers with/without 'signal' option, aborted *before* dispatch", function () {
const eventBus = new EventBus();
const ac = new AbortController();
let multipleCount = 0,
noneCount = 0;
eventBus.on("test", function () {
multipleCount++;
});
eventBus.on(
"test",
function () {
noneCount++;
},
{ signal: ac.signal }
);
ac.abort();
eventBus.dispatch("test");
eventBus.dispatch("test");
eventBus.dispatch("test");
expect(multipleCount).toEqual(3);
expect(noneCount).toEqual(0);
});
it("dispatch event to handlers with/without 'signal' option, aborted *after* dispatch", function () {
const eventBus = new EventBus();
const ac = new AbortController();
let multipleCount = 0,
onceCount = 0;
eventBus.on("test", function () {
multipleCount++;
});
eventBus.on(
"test",
function () {
onceCount++;
},
{ signal: ac.signal }
);
eventBus.dispatch("test");
ac.abort();
eventBus.dispatch("test");
eventBus.dispatch("test");
expect(multipleCount).toEqual(3);
expect(onceCount).toEqual(1);
});
it("should not re-dispatch to DOM", async function () {
if (isNodeJS) {
pending("Document is not supported in Node.js.");