Async Page Function?

My workflow is like

// save data
// return data

It works well in my local dev env, but does not send email when deployed to cloudflare page. I have to change it to

// this one calls API to send email
await sendEmailViaApi();

to make it work.

Could anyone explain why I have to add await to make it work in page function?

Pending promises will be cancelled if your response is returned.
You can use waitUntil to run stuff even after a response is returned

export function onRequest({ waitUntil }) {
  return new Response('hello world');

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.