Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(mascots): the clock asks for no frame once its last mascot has gone (#4205)

Milind Sonif52effc1a587
diff --git a/src/components/mascot-clock.test.ts b/src/components/mascot-clock.test.ts
index f379e6056a..ad240931bc 100644
--- a/src/components/mascot-clock.test.ts
+++ b/src/components/mascot-clock.test.ts
@@ -107,6 +107,17 @@ describe("mascot clock", () => {
expect(paintedAt.size).toBeLessThanOrEqual(63);
});
+ it("asks for no frame once the last mascot has gone, with a timer already set", () => {
+ const fake = fakeEnvironment();
+ const clock = createMascotClock(fake.env);
+ const ticket = clock.add(() => 500);
+ fake.advance(20);
+ const asked = fake.stats.frameRequests;
+ ticket.remove();
+ fake.advance(1000);
+ expect(fake.stats.frameRequests).toBe(asked);
+ });
+
it("asks for no frames while every mascot is still, and one frame when woken", () => {
const fake = fakeEnvironment();
const clock = createMascotClock(fake.env);
diff --git a/src/components/mascot-clock.ts b/src/components/mascot-clock.ts
index c80422290d..863564bb65 100644
--- a/src/components/mascot-clock.ts
+++ b/src/components/mascot-clock.ts
@@ -62,7 +62,7 @@ export function createMascotClock(env: ClockEnvironment): MascotClock {
}
timerHandle = env.setTimer(() => {
timerHandle = null;
- if (frameHandle === null && !hidden) frameHandle = env.requestFrame(run);
+ if (frameHandle === null && !hidden && entries.size) frameHandle = env.requestFrame(run);
}, wait - TIMER_LEAD_MS);
};