Fix shutdown handling, error management, and process lifecycle issues

🤖 Generated with [OpenCode](https://opencode.ai)

Co-Authored-By: OpenCode <noreply@opencode.ai>
This commit is contained in:
Dax Raad
2025-06-10 18:58:47 -04:00
parent ca3c22dc12
commit 28f5cbbfe9
7 changed files with 89 additions and 66 deletions

View File

@@ -97,7 +97,7 @@ export namespace App {
log.info("registering service", { name: key })
services.set(key, {
state: init(app.info),
shutdown: shutdown,
shutdown,
})
}
return services.get(key)?.state as State
@@ -108,14 +108,15 @@ export namespace App {
return ctx.use().info
}
export async function provide<T extends (app: Info) => any>(
export async function provide<T>(
input: { cwd: string; version: string },
cb: T,
cb: (app: Info) => Promise<T>,
) {
const app = await create(input)
return ctx.provide(app, async () => {
const result = await cb(app.info)
for (const [key, entry] of app.services.entries()) {
if (!entry.shutdown) continue
log.info("shutdown", { name: key })
await entry.shutdown?.(await entry.state)
}