happy-server/sources/utils/forever.ts
2025-07-26 01:16:22 -07:00

24 lines
668 B
TypeScript

import { AbortedExeption } from "./aborted";
import { backoff } from "./backoff";
import { keepAlive, shutdownSignal } from "./shutdown";
export async function forever(
name: string,
callback: () => Promise<void>
) {
keepAlive(name, async () => {
await backoff(async () => {
while (!shutdownSignal.aborted) {
try {
await callback();
} catch (error) {
if (AbortedExeption.isAborted(error)) {
break;
} else {
throw error;
}
}
}
});
});
}