You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just found out that it works in development environment but it doesn't work as expected when deployed on cloudflare throught nuxthub. event.waitUntil gets blocked and the user waits for the response when it shouldn't happen like that. I tried this and it works:
constwaitFor=(ms: number)=>newPromise((resolve)=>setTimeout(resolve,ms))asyncfunctionbackgroundTask(id: number){awaitwaitFor(5000)console.log(`Task ${id} is done!`)}exportdefaultdefineEventHandler((event)=>{constcfCtx=event.context.cloudflare.contextconsttaskId=Math.round(Math.random()*1000)event.context.taskId=taskIdletnow=newDate()console.log('Time before backgroundTask : '+now.toLocaleTimeString())cfCtx.waitUntil(backgroundTask(taskId))now=newDate()return`Task ${taskId} is running in background... : ${now.toLocaleTimeString()}`})
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered:
Environment
Nuxt 3.12.4 with Nitro 2.9.7 with cloudflare pages preset through nuxthub
Reproduction
https://stackblitz.com/edit/github-ch89s7?file=routes%2Findex.ts,plugins%2Fbackground.ts
Describe the bug
I just found out that it works in development environment but it doesn't work as expected when deployed on cloudflare throught nuxthub. event.waitUntil gets blocked and the user waits for the response when it shouldn't happen like that. I tried this and it works:
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: