Skip to content

Commit 37c1f6c

Browse files
committed
watcher: use a while loop
1 parent 49bc239 commit 37c1f6c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

watcher/src/workers/supervisor.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Worker } from 'worker_threads';
22
import { HB_INTERVAL, WorkerData } from '../consts';
33
import { getLogger } from '../utils/logger';
4-
import { Mode, getMode, getNetwork } from '@wormhole-foundation/wormhole-monitor-common';
4+
import { Mode, getMode, getNetwork, sleep } from '@wormhole-foundation/wormhole-monitor-common';
55
import { Chain, Network } from '@wormhole-foundation/sdk-base';
66

77
interface WorkerInfo {
@@ -39,8 +39,8 @@ function spawnWorker(data: WorkerData) {
3939
logger.debug('Finished spawning worker:', workerName);
4040
}
4141

42-
function monitorWorkers() {
43-
setInterval(async () => {
42+
async function monitorWorkers(): Promise<void> {
43+
while (true) {
4444
for (const [workerName, workerInfo] of Object.entries(workers)) {
4545
logger.debug(
4646
`Checking worker ${workerName} with lastHB of ${new Date(workerInfo.lastHB)}...`
@@ -52,7 +52,8 @@ function monitorWorkers() {
5252
spawnWorker(workerInfo.data);
5353
}
5454
}
55-
}, HB_INTERVAL);
55+
await sleep(HB_INTERVAL);
56+
}
5657
}
5758

5859
export function startSupervisor(supportedChains: Chain[]) {

0 commit comments

Comments
 (0)