Skip to content

NamesMT/hono-wait-until

Repository files navigation

hono-wait-until TypeScript heart icon

npm version npm downloads Codecov Bundlejs jsDocs.io

hono-wait-until is a simple wrapper for wait-until-generalized, which "Fake waitUntil in AWS Lambda and other platforms that don't support it.".

It basically waits for all async tasks to complete before returning the response, so the platform won't kill your app with uncompleted async tasks.

Usage

Install package:

# npm
npm install hono-wait-until

# yarn
yarn add hono-wait-until

# pnpm (recommended)
pnpm install hono-wait-until

Import:

import type { WaitUntilList } from 'hono-wait-until'
import {
  waitUntil, // Optional helper function instead of accessing via context
  waitUntilMiddleware,
} from 'hono-wait-until'

const app = new Hono<{ Variables: { waitUntilList: WaitUntilList } }>()
  // Preferably, use the waitUntilMiddleware as early as you can.
  .use(waitUntilMiddleware())
  .get('/context', async (c) => {
    const waitUntilList = c.get('waitUntilList')
    waitUntilList.waitUntil(sleep(300))

    return c.text(`Using waitUntil via context variable`)
  })
  .get('/helper', async (c) => {
    waitUntil(sleep(300), c)

    return c.text(`Using waitUntil via helper function`)
  })

Roadmap

  • Become the legendary 10000x developer

License License

MIT License © 2025 NamesMT