Add "clean up timer if necessary" utility

This commit is contained in:
Evan Hahn 2022-02-25 12:37:15 -06:00 committed by GitHub
parent c2a65306e2
commit 052a8e65e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 150 additions and 137 deletions

View file

@ -1,8 +1,9 @@
// Copyright 2018-2021 Signal Messenger, LLC
// Copyright 2018-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import EventEmitter from 'events';
import * as log from './logging/log';
import { clearTimeoutIfNecessary } from './util/clearTimeoutIfNecessary';
const POLL_INTERVAL_MS = 5 * 1000;
const IDLE_THRESHOLD_MS = 20;
@ -31,10 +32,8 @@ export class IdleDetector extends EventEmitter {
delete this.handle;
}
if (this.timeoutId) {
clearTimeout(this.timeoutId);
delete this.timeoutId;
}
clearTimeoutIfNecessary(this.timeoutId);
delete this.timeoutId;
}
private scheduleNextCallback() {