Skip to content

Conversation

@threepointone
Copy link
Collaborator

Introduces an internal keep-alive WebSocket endpoint and the experimental_waitUntil method to allow Durable Objects to remain alive while executing long-running async functions. This mechanism uses a self-connecting WebSocket with periodic pings and requires the 'enable_ctx_exports' compatibility flag. Additional handling is added to ignore keep-alive sockets in WebSocket event methods.

Based on @eastlondoner's https://github.com/eastlondoner/better-wait-until

Introduces an internal keep-alive WebSocket endpoint and the experimental_waitUntil method to allow Durable Objects to remain alive while executing long-running async functions. This mechanism uses a self-connecting WebSocket with periodic pings and requires the 'enable_ctx_exports' compatibility flag. Additional handling is added to ignore keep-alive sockets in WebSocket event methods.

Based on @eastlondoner's https://github.com/eastlondoner/better-wait-until
@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2025

🦋 Changeset detected

Latest commit: e4d4f6d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
partyserver Patch
hono-party Patch
partysub Patch
partysync Patch
partywhen Patch
y-partyserver Patch
@partyserver/fixture-chat Patch
@partyserver/fixture-globe Patch
@partyserver/fixture-hono Patch
@partyserver/fixture-tiptap-yjs Patch
@partyserver/fixture-tldraw Patch
@partyserver/fixture-todo-sync Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@threepointone threepointone changed the title Add experimental waitUntil API for long-running tasks Add experimental_waitUntil API for long-running tasks Dec 19, 2025
Replaces manual timeout tracking with a Promise.race approach for cleaner and more reliable timeout handling in the async function. This improves code clarity and ensures the function properly rejects if the timeout is reached.
Comment on lines +645 to +663
const exports = (
this.ctx as DurableObjectState & { exports?: Record<string, unknown> }
).exports;
if (!exports) {
throw new Error(
"waitUntil requires the 'enable_ctx_exports' compatibility flag. " +
'Add it to your wrangler.jsonc: { "compatibility_flags": ["enable_ctx_exports"] }'
);
}

const namespace = exports[this.#ParentClass.name] as
| DurableObjectNamespace
| undefined;
if (!namespace) {
throw new Error(
`Could not find namespace for ${this.#ParentClass.name} in ctx.exports. ` +
"Make sure the class name matches your Durable Object binding."
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx exports is fire

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the flag is actually on by default now too

@threepointone threepointone merged commit fcc4a30 into main Dec 19, 2025
4 checks passed
@threepointone threepointone deleted the wait-until branch December 19, 2025 14:00
@threepointone threepointone mentioned this pull request Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants