Rewrite WallClockListener as onTimeTravel

This commit is contained in:
Evan Hahn 2022-05-31 16:22:31 +00:00 committed by GitHub
parent 11cfb4f76f
commit 6668348197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 30 deletions

View 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);
}