Commit 8ef2ff0
docs(components): document app cleanup on shutdown via scope 'close' (#647)
* docs(components): document app cleanup on shutdown via scope 'close'
The only coverage of shutdown cleanup was a single line in the Scope
events list ("Emitted after `scope.close()` is called"), which reads as
if the plugin author calls `scope.close()` themselves. Nothing stated
that Harper calls it during shutdown and graceful restart, which is the
reason an application would listen for the event at all.
- Add a "Cleanup on Shutdown" section to plugin-api.md with the
`scope.once('close', ...)` pattern, covering the shutdown sequence:
async listeners are awaited, cleanup is bounded by the termination
backstop, a rejecting listener is logged and stops the wait on its
siblings, and each worker cleans up independently.
- Clarify the `'close'` event and `scope.close()` entries in place and
link them to the new section.
- Add a "Shutdown Cleanup" pointer to applications.md so the
application-building audience finds it (that page had no occurrence of
"cleanup", "shutdown", or "teardown").
- Record the v5.1.3 behavior change in the Version History list.
Verified against harper: componentLoader.ts:700 calls `scope.close()` on
the SHUTDOWN ITC message, restartWorkers posts the same message, and
Scope.ts:275-288 awaits promises returned by 'close' listeners.
Closes #604
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* docs(components): add v5.1.3 changed badge to scope.close()
Review feedback on #647: scope.close() awaits promises returned by
'close' listeners as of v5.1.3 (v5.1.2 emitted 'close' without
awaiting). Per CONTRIBUTING.md, behavior changes to existing surface
get a standalone <VersionBadge type="changed" /> below the heading.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* docs(components): scope shutdown cleanup to what needs an explicit hook
Address review feedback on the new shutdown cleanup coverage.
The section listed timers and open connections as things an application
is responsible for tearing down. Node closes timers and sockets itself
when a thread exits, so presenting them as the app's job is misleading.
Reframe both the plugin-api.md section and the applications.md pointer
around work that genuinely needs a hook: flushing buffered writes,
deregistering from an external service, releasing a distributed lock,
or closing a connection whose remote side expects a graceful goodbye.
Also drop the incorrect justification for `scope.once()`. It claimed
`once` avoids leaving a listener behind during a reload, but
`Scope.close()` detaches its `'close'` listeners as part of closing and
a reload builds a new Scope, so `on()` cannot strand a listener on a
closed scope either. Recommend `once()` on the honest grounds that
closing is a one-time lifecycle event.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 3356abc commit 8ef2ff0
2 files changed
Lines changed: 50 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
69 | 86 | | |
70 | 87 | | |
71 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
193 | 197 | | |
194 | 198 | | |
195 | 199 | | |
| |||
379 | 383 | | |
380 | 384 | | |
381 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
382 | 412 | | |
383 | 413 | | |
384 | 414 | | |
| |||
427 | 457 | | |
428 | 458 | | |
429 | 459 | | |
| 460 | + | |
0 commit comments