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.
# npm
npm install hono-wait-until
# yarn
yarn add hono-wait-until
# pnpm (recommended)
pnpm install hono-wait-until
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`)
})
- Become the legendary 10000x developer