next.js
41e1dcae - Improve internal waitUntil utility (#56720)

Commit
2 years ago
Improve internal waitUntil utility (#56720) ⚠️ This is an internal API and will be removed soon. Please do not use. Refactors #56404 to have a better internal API used by both Edge SSR and Edge Route Handlers. This new API can buffer non-synchronously created "waitUntil"s even after the response has been returned, just need to make sure that there's at least one "waitUntil" queued. E.g.: ```js async function handler() { internal_runWithWaitUntil(async () => { // ← no await await taskA() internal_runWithWaitUntil(async () => { // ← no await await longRunningTaskB() }) await taskC() }) return Response(...) } ``` Internally, the "waitUntil" promise will resolve after all tasks are finished. cc @ijjk @cramforce @feedthejim as we've synced about some of the details here. Not using ALS because of some promise-related issues.
Author
Parents
Loading