Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event.waitUntil is not available in defineCachedEventHandler #3063

Open
DTesch-Level-R opened this issue Feb 3, 2025 · 0 comments
Open

event.waitUntil is not available in defineCachedEventHandler #3063

DTesch-Level-R opened this issue Feb 3, 2025 · 0 comments

Comments

@DTesch-Level-R
Copy link

Environment

nitro v2.10.4

Reproduction

export default defineCachedEventHandler(async (event) => {
event.waitUntil(asyncTask()); // ❌ Throws error: "event.waitUntil is not a function"

return { success: true };
}, { maxAge: 60 });

export default defineEventHandler(async (event) => {
event.waitUntil(new Promise((resolve) => setTimeout(resolve, 3000))); // ✅ Works as expected
});

Describe the bug

When using defineEventHandler(), calling event.waitUntil() works as expected and allows asynchronous tasks to continue running after the response has been sent. However, inside defineCachedEventHandler(), event.waitUntil() is undefined, causing an error when attempting to use it.

Is this expected behaviour?
If event.waitUntil() is unavailable, how can I ensure my Cloudflare Worker does not terminate my defineCachedEventHandler() before an asynchronous function completes?

Additional context

No response

Logs

@TheAlexLichter TheAlexLichter changed the title event.waitUntil is not a function event.waitUntil is not available in defineCachedEventHandler Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant