fix: provide waitUntil to Gateway listener so it stays alive

The startGatewayListener returns immediately without waitUntil because
it's designed for serverless. In standalone mode we need to provide
a waitUntil function that tracks background tasks and wait for them.
This commit is contained in:
Bentlybro
2026-03-31 17:25:32 +00:00
parent 652c12768e
commit c1d6689215

View File

@@ -56,12 +56,24 @@ async function main() {
const runGateway = async () => {
while (true) {
try {
await discord.startGatewayListener(
{},
// Track background tasks so the listener stays alive
const pendingTasks: Promise<unknown>[] = [];
const waitUntil = (task: Promise<unknown>) => {
pendingTasks.push(task);
};
const response = await discord.startGatewayListener(
{ waitUntil },
10 * 60 * 1000, // 10 minutes
undefined,
webhookUrl
);
// Wait for any background tasks to complete
if (pendingTasks.length > 0) {
await Promise.allSettled(pendingTasks);
}
console.log("[gateway] Listener ended, restarting...");
} catch (err) {
console.error("[gateway] Error, restarting in 5s:", err);