Skip to content

Commit

Permalink
Update timer when removing timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mfal committed Sep 6, 2023
1 parent 2261ac0 commit 8835673
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/ConsolidatedTimeout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ test("Callback is triggered instantly when adding due timeout while already runn
timeout.addTimeout({ milliseconds: 500 });
expect(callback).toHaveBeenCalledTimes(1);
});

test("Removing last timeout will not trigger callback", (): void => {
timeout.start();
const removeTimeout = timeout.addTimeout({ milliseconds: 1000 });
removeTimeout();
testCallbackIsNotCalledAfter(1000);
});
1 change: 1 addition & 0 deletions src/lib/ConsolidatedTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class ConsolidatedTimeout {

return () => {
this.timeoutMillis.delete(timeoutMs);
this.startNextTimeout();
};
}

Expand Down

0 comments on commit 8835673

Please sign in to comment.