forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal-lifecycle.ts
More file actions
28 lines (25 loc) · 925 Bytes
/
Copy pathglobal-lifecycle.ts
File metadata and controls
28 lines (25 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { GlobalBus } from "@/bus/global"
import { InstanceStore } from "@/project/instance-store"
import { Effect } from "effect"
import { Event } from "./event"
export const emitGlobalDisposed = Effect.sync(() =>
GlobalBus.emit("event", {
directory: "global",
payload: {
type: Event.Disposed.type,
properties: {},
},
}),
)
export const disposeAllInstancesAndEmitGlobalDisposed = Effect.fn("Server.disposeAllInstancesAndEmitGlobalDisposed")(
function* (options?: { swallowErrors?: boolean }) {
const store = yield* InstanceStore.Service
yield* Effect.gen(function* () {
yield* options?.swallowErrors
? store.disposeAll().pipe(Effect.catchCause((cause) => Effect.logWarning("global disposal failed", { cause })))
: store.disposeAll()
yield* emitGlobalDisposed
}).pipe(Effect.uninterruptible)
},
)
export * as GlobalLifecycle from "./global-lifecycle"