diff --git a/src/index.ts b/src/index.ts index 23d2d67..29a11bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,11 +22,7 @@ try { console.error("Heimdall verse publication failed on interval:", error); }); }, versePulseIntervalMs); - const healthTimer = setInterval(() => { - void publishHealthState().catch((error) => { - console.error("Heimdall signed health publication failed on interval:", error); - }); - }, healthPulseIntervalMs); + void runHealthPulseLoop(); verseTimer.unref?.(); } catch (error) { app.log.error(error); @@ -47,3 +43,12 @@ async function publishHealthState(): Promise { observedAt: pulse.updatedAt, }); } + +async function runHealthPulseLoop(): Promise { + for (;;) { + await new Promise((resolve) => setTimeout(resolve, healthPulseIntervalMs)); + await publishHealthState().catch((error) => { + console.error("Heimdall signed health publication failed on interval:", error); + }); + } +}