You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-internal/engine/sleep-sequence.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Removing `preventSleep` deleted both predicate branches. Any future sleep-affect
39
39
40
40
-`start_grace(reason)` fires at the start of `SleepGrace` / `DestroyGrace`. It cancels the sleep idle timer, cancels the actor abort signal (`actor_abort_signal`), installs a `SleepGraceState` with the effective grace deadline, and resets the sleep timer to arm the grace tick.
41
41
- The actor abort signal is a soft signal: "shutdown has started, please wrap up." User code observes it via `c.abortSignal`. It does not force-stop work.
42
-
-For destroy, the abort signal may fire earlier than grace entry because `ctx.destroy()` cancels the abort token immediately via `mark_destroy_requested(...)`.
42
+
-Destroy requests also use the normal grace path. The actor abort signal fires when destroy grace starts.
* The handler receives an abort signal via `c.abortSignal` and a
1230
-
* `c.aborted` alias for loop checks. Use these to gracefully exit.
1230
+
* `c.aborted` alias. Use these to gracefully exit when shutdown starts.
1231
1231
*
1232
1232
* If this handler exits, the actor will follow the normal idle sleep timeout
1233
1233
* once it becomes idle.
@@ -1770,7 +1770,7 @@ export const DocActorOptionsSchema = z
1770
1770
.number()
1771
1771
.optional()
1772
1772
.describe(
1773
-
`Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler abort wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: ${DEFAULT_SLEEP_GRACE_PERIOD}.`,
1773
+
`Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: ${DEFAULT_SLEEP_GRACE_PERIOD}.`,
Copy file name to clipboardExpand all lines: website/src/content/docs/actors/actions.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -325,7 +325,7 @@ Actions have a single return value. To stream realtime data in response to an ac
325
325
326
326
## Canceling Long-Running Actions
327
327
328
-
For operations that should be cancelable on-demand, create your own `AbortController` and chain it with `c.abortSignal`for automatic cleanup on actor shutdown.
328
+
For operations that should be cancelable on-demand, create your own `AbortController`. Chain it with `c.abortSignal`so actor shutdown also cancels the operation.
Copy file name to clipboardExpand all lines: website/src/content/docs/actors/index.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -466,7 +466,7 @@ const userAccount = actor({
466
466
467
467
### Lifecycle Hooks
468
468
469
-
Actors support hooks for initialization, background processing, connections, networking, and state changes. Use `run` for long-lived background loops, and exit cleanly on shutdown with `c.aborted` or `c.abortSignal`.
469
+
Actors support hooks for initialization, background processing, connections, networking, and state changes. Use `run` for long-lived background loops, and use `c.aborted` or `c.abortSignal` for graceful shutdown.
// Wait 1 second. Final shutdown also resolves this wait.
308
308
awaitnewPromise<void>((resolve) => {
309
309
const timeout =setTimeout(resolve, 1000);
310
310
c.abortSignal.addEventListener("abort", () => {
@@ -876,7 +876,7 @@ When an actor sleeps or is destroyed, it enters the graceful shutdown window:
876
876
877
877
1.`c.abortSignal` fires and `c.aborted` becomes `true`. New connections and dispatch are rejected. Alarm timeouts are cancelled. On sleep, scheduled events are persisted and will be re-armed when the actor wakes.
878
878
2.`onSleep` or `onDestroy` and `onDisconnect` for each closing connection run during the same window. User `waitUntil` promises and async raw WebSocket handlers are drained. Hibernatable WebSocket connections are preserved on sleep and closed on destroy.
879
-
3. Once graceful work has completed, state is saved and the database is cleaned up.
879
+
3. Once graceful work has completed, state is saved and final cleanup runs.
880
880
881
881
The entire window is bounded by `sleepGracePeriod` on both sleep and destroy. Defaults to 15 seconds. If the window is exceeded, the actor proceeds to state save anyway.
0 commit comments