addEventListener("fetch", (event) => {
event.respondWith(
(async function () {
const response = await doCalculateAResponse(event.request);
event.waitUntil(
(async function () {
await doSomeAsyncStuff(); // optional
// Wait for the event to be consumed by the browser
await event.handled;
return doFinalStuff(); // Finalize AFTER the event has been consumed
})(),
);
return response;
})(),
);
});FetchEvent: handled property / notebook
FetchEvent: handled property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.