mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-27 05:38:12 +00:00
Clean up timeout in waitForOnline
This commit is contained in:
@@ -14,6 +14,8 @@ export function waitForOnline(
|
||||
return;
|
||||
}
|
||||
|
||||
let timeoutId: undefined | ReturnType<typeof setTimeout>;
|
||||
|
||||
const listener = () => {
|
||||
cleanup();
|
||||
resolve();
|
||||
@@ -21,12 +23,15 @@ export function waitForOnline(
|
||||
|
||||
const cleanup = () => {
|
||||
onlineEventTarget.removeEventListener('online', listener);
|
||||
if (typeof timeoutId === 'number') {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
};
|
||||
|
||||
onlineEventTarget.addEventListener('online', listener);
|
||||
|
||||
if (timeout !== undefined) {
|
||||
setTimeout(() => {
|
||||
timeoutId = setTimeout(() => {
|
||||
cleanup();
|
||||
reject(new Error('waitForOnline: did not come online in time'));
|
||||
}, timeout);
|
||||
|
||||
Reference in New Issue
Block a user