Hello chat! I have an inquiry about `ctx.waitUntil`. **I'm trying to use it in my worker to send tw

Hello chat!
I have an inquiry about
ctx.waitUntil
.
I'm trying to use it in my worker to send two
fetch
es
(a callback response and a followup message from Discord's Bot API, for context).
When I'm running the worker locally it can send both
fetch
es just fine, but when its running on the cloud, Discord only receives the first request.
Admittedly, I'm not an expert in async programming, but I don't think I've done wrong since its working locally.
Asking on chance that maybe someone has experience with this.
I have a suspicion that I may have used async/await wrongly.

Posting this message is the last thing I'm doing before bed, so sorry if you'd like to see the actual code; I'll post it later if requested.
Simplified code below...
async fetch(request, env, ctx){
  ctx.waitUntil(
    // Wrapping it in a promise worked for someone else
    new Promise(async function (resolve) {
        await runCommand()
        return resolve(undefined)
    }))
  return new Response("Hello World!")
}

async function runCommand(){
  await sendCallback() // Discord only recieves this one
  // do command stuff
  await sendFollowup()
}

async function sendCallback(){ await fetch() }
async function sendFollowup(){ await fetch() }
Was this page helpful?