feat(functions): implement waitUntil runtime integration#207
Merged
Conversation
Forward the deferred promise to the Neon Functions runtime via its
per-invocation context (globalThis[NEON_FUNCTIONS_CONTEXT], a
Symbol.for("@neondatabase/functions/request-context")), keeping the
invocation alive until the promise settles. Matches Vercel's spec: a
non-Promise argument throws TypeError, and the function no-ops when no
runtime context is present (local dev, tests, non-Neon hosts). Export
NEON_FUNCTIONS_CONTEXT as the documented runtime contract.
…LocalStorage context
Switch waitUntil from a factory to a direct call (waitUntil(promise)) to mirror
@vercel/functions. Carry per-invocation context in an AsyncLocalStorage published on
globalThis[NEON_FUNCTIONS_CONTEXT] as a `{ get() }` provider (Vercel/Next contract),
fixing context clobbering across concurrent invocations. Add runWithRequestContext for
the runtime to bind a context per invocation.
jeff-at-neon
approved these changes
Jun 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
waitUntil()in@neondatabase/functions(replaces the no-op placeholder).waitUntil()now forwards the promise to the Neon Functions runtime via its per-invocation context:globalThis[NEON_FUNCTIONS_CONTEXT], whereNEON_FUNCTIONS_CONTEXT = Symbol.for("@neondatabase/functions/request-context")(mirrors Vercel's@vercel/request-contextconvention).waitUntilspec: a non-Promiseargument throwsTypeError.waitUntil()is called at module scope.NEON_FUNCTIONS_CONTEXTas the documented runtime contract; README updated; changeset added (minor).Open question for review
The global context key is not yet confirmed against the runtime host — please verify
Symbol.for("@neondatabase/functions/request-context")(and the flat.waitUntilshape vs. a Vercel-style.get()accessor) matches what the Functions runtime actually publishes. If it doesn't,waitUntilwill silently no-op in production.Test plan
pnpm tsc(typecheck)pnpm test:ci(5 tests, realglobalThiswiring, no mocks)pnpm build(tsdown)