fix(opencode): own effect sqlite lifecycle in layers
This commit is contained in:
@@ -10,6 +10,7 @@ import { Vcs } from "@/project/vcs"
|
||||
import { Snapshot } from "@/snapshot"
|
||||
import { Bus } from "@/bus"
|
||||
import { Config } from "@/config/config"
|
||||
import { lazy } from "@/util/lazy"
|
||||
import * as Observability from "@opencode-ai/core/effect/observability"
|
||||
import { memoMap } from "@opencode-ai/core/effect/memo-map"
|
||||
|
||||
@@ -26,4 +27,20 @@ export const BootstrapLayer = Layer.mergeAll(
|
||||
Bus.defaultLayer,
|
||||
).pipe(Layer.provide(Observability.layer))
|
||||
|
||||
export const BootstrapRuntime = ManagedRuntime.make(BootstrapLayer, { memoMap })
|
||||
const rt = lazy(() => ManagedRuntime.make(BootstrapLayer, { memoMap }))
|
||||
type Runtime = Pick<ReturnType<typeof rt>, "runPromise" | "dispose">
|
||||
|
||||
export const BootstrapRuntime: Runtime = {
|
||||
runPromise(effect, options) {
|
||||
return rt().runPromise(effect, options)
|
||||
},
|
||||
async dispose() {
|
||||
const current = rt.peek()
|
||||
if (!current) return
|
||||
try {
|
||||
await current.dispose()
|
||||
} finally {
|
||||
if (rt.peek() === current) rt.reset()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user