Rewrite WallClockListener
as onTimeTravel
This commit is contained in:
parent
11cfb4f76f
commit
6668348197
5 changed files with 82 additions and 30 deletions
18
ts/util/startTimeTravelDetector.ts
Normal file
18
ts/util/startTimeTravelDetector.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2017-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
const INTERVAL = 1000;
|
||||
|
||||
export function startTimeTravelDetector(callback: () => unknown): void {
|
||||
let lastTime = Date.now();
|
||||
setInterval(() => {
|
||||
const currentTime = Date.now();
|
||||
|
||||
const sinceLastTime = currentTime - lastTime;
|
||||
if (sinceLastTime > INTERVAL * 2) {
|
||||
callback();
|
||||
}
|
||||
|
||||
lastTime = currentTime;
|
||||
}, INTERVAL);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue