Add "clean up timer if necessary" utility
This commit is contained in:
parent
c2a65306e2
commit
052a8e65e2
23 changed files with 150 additions and 137 deletions
|
@ -1,6 +1,8 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// Copyright 2021-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { clearTimeoutIfNecessary } from './clearTimeoutIfNecessary';
|
||||
|
||||
export function waitForOnline(
|
||||
navigator: Readonly<{ onLine: boolean }>,
|
||||
onlineEventTarget: EventTarget,
|
||||
|
@ -23,9 +25,7 @@ export function waitForOnline(
|
|||
|
||||
const cleanup = () => {
|
||||
onlineEventTarget.removeEventListener('online', listener);
|
||||
if (typeof timeoutId === 'number') {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
clearTimeoutIfNecessary(timeoutId);
|
||||
};
|
||||
|
||||
onlineEventTarget.addEventListener('online', listener);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue