mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 04:22:07 +00:00
This PR makes `waitUntil` consistent when interacting with it via `vc
dev`. That includes:
**be possible to call `waitUntil` from the context second argument in
web handlers functions (Node.js & Edge)**:
```js
export function GET(request, { waitUntil }) {
waitUntil(fetch('https://vercel.com'));
return new Response('OK');
}
```
**be possible to call `waitUntil` imported from `@vercel/functions`**
(Node.js & Edge):
```js
import { waitUntil } from '@vercel/functions';
export function GET(request) {
waitUntil(fetch('https://vercel.com'));
return new Response('OK');
}
```
Additionally, `@vercel/functions` can be adopted for other framework to
take advantage of this pattern at Vercel.
---------
Co-authored-by: Javi Velasco <javier.velasco86@gmail.com>
13 lines
254 B
JavaScript
13 lines
254 B
JavaScript
function lazyError() {
|
|
return new Promise((_, reject) => {
|
|
setTimeout(() => {
|
|
reject(new Error('oh no'));
|
|
}, 100);
|
|
});
|
|
}
|
|
|
|
export function GET(_, ctx) {
|
|
ctx.waitUntil(lazyError());
|
|
return Response.json({ keys: Object.keys(ctx) });
|
|
}
|