#5342·hono

Feature Request: Support `waitUntil` in middleware for background task scheduling

Author: fbwe425Created Sep 6, 2026Updated Sep 8, 2026

Summary

When building serverless applications with Hono on Cloudflare Workers or similar edge runtimes, it's common to need waitUntil() from the execution context to fire-and-forget background tasks (e.g. logging, analytics, cache warming) without blocking the response.

Problem

Currently, accessing ctx.executionCtx.waitUntil() inside Hono middleware requires either:

  1. Passing the execution context manually through every handler
  2. Using a workaround via c.env to store it

There's no idiomatic, first-class way to use waitUntil in middleware.

Proposed Solution

Expose a c.waitUntil(promise) helper on the Hono Context object, similar to how c.executionCtx already works but with a more ergonomic interface:

typescript
app.use(async (c, next) => {
  await next()
  // Fire-and-forget: log request after response is sent
  c.waitUntil(logRequest(c.req.raw))
})

Why This Matters

  • Cloudflare Workers, Deno Deploy, and Vercel Edge all support waitUntil semantics
  • Frameworks like Remix and Next.js are adding similar patterns
  • Makes it easier to add observability (logging, tracing) without impacting response latency

Additional Context

Would love to hear if there's a reason this hasn't been added, or if there's a recommended pattern I'm missing!