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
In the cache docs, there's a part regarding edge workers that specifies the handling of edge workers with waitUntil
In edge workers, the instance is destroyed after each request. Nitro automatically uses event.waitUntil to keep the instance alive while the cache is being updated while the response is sent to the client.
This is really interesting. My question is twofold:
are we talking about the web API waitUntil or some environment specific feature like Vercel's wailtUntil (triggered based on the deploy target),
could we leverage this API to manually take advantage of it?
I imagine that if 1. is just a call to the web API's wailtUntil, there's not a huge benefit in making it a public API (one can just use the web API straight). But if 1. is environment aware and uses the right API based on context, 2. would be golden!
Let met clarify this with a situation and exemples:
// /server/api/admin/orders/index.post.js// ... previous logic// Here we'd like to send a response as soon as our DB queries are finished// and we want to send the proper notifications as wellreturnPromise.all(dbOps).then(async()=>{// In an ideal situation, this is just fire & forget// but in serverless, not awaiting for it means the process is terminated as soon as the function returns a responseif(body.payment){awaitsendOrderNotif(orderId,body.paymentStatus==='paid' ? 'completePayment' : 'partialPayment',body.payment.amount);}// If we don't await, when this is done (the eventHandler returns)// if sendOrderNotif hasn't finished (which is almost sure for async logic) and it's abortedreturnsetResponseStatus(event,204);}).catch(handleApiError);
Given this exemple, in a classical NodeJS setup, there's no need to await sendOrderNotif. But in serverless, we need to wait for it to finish, creating an artificial delay before the client can get its response.
Where the Nitro unified API would shine is if you can just call, say nitro.waitUntil and it automatically uses what's best under the hood:
Vercel's waitUntil for its NodeJS runtime,
web API for V8 based serverless runtimes (cloufdlare, Vercel's edge…)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In the cache docs, there's a part regarding edge workers that specifies the handling of edge workers with
waitUntilThis is really interesting. My question is twofold:
waitUntilor some environment specific feature like Vercel'swailtUntil(triggered based on the deploy target),I imagine that if 1. is just a call to the web API's
wailtUntil, there's not a huge benefit in making it a public API (one can just use the web API straight). But if 1. is environment aware and uses the right API based on context, 2. would be golden!Let met clarify this with a situation and exemples:
Given this exemple, in a classical NodeJS setup, there's no need to await
sendOrderNotif. But in serverless, we need to wait for it to finish, creating an artificial delay before the client can get its response.Where the Nitro unified API would shine is if you can just call, say
nitro.waitUntiland it automatically uses what's best under the hood:Beta Was this translation helpful? Give feedback.
All reactions