MCPcopy
hub / github.com/anomalyco/opencode / make

Function make

packages/opencode/src/effect/instance-state.ts:26–45  ·  view source on GitHub ↗
(
  init: (ctx: InstanceContext) => Effect.Effect<A, E, R | Scope.Scope>,
)

Source from the content-addressed store, hash-verified

24export const directory = Effect.map(context, (ctx) => ctx.directory)
25
26export const make = <A, E = never, R = never>(
27 init: (ctx: InstanceContext) => Effect.Effect<A, E, R | Scope.Scope>,
28): Effect.Effect<InstanceState<A, E, Exclude<R, Scope.Scope>>, never, R | Scope.Scope> =>
29 Effect.gen(function* () {
30 const cache = yield* ScopedCache.make<string, A, E, R>({
31 capacity: Number.POSITIVE_INFINITY,
32 lookup: () =>
33 Effect.gen(function* () {
34 return yield* init(yield* context)
35 }),
36 })
37
38 const off = registerDisposer((directory) => Effect.runPromise(ScopedCache.invalidate(cache, directory)))
39 yield* Effect.addFinalizer(() => Effect.sync(off))
40
41 return {
42 [TypeId]: TypeId,
43 cache,
44 }
45 })
46
47export const get = <A, E, R>(self: InstanceState<A, E, R>) =>
48 Effect.gen(function* () {

Callers

nothing calls this directly

Calls 4

registerDisposerFunction · 0.90
syncMethod · 0.80
initFunction · 0.50
makeMethod · 0.45

Tested by

no test coverage detected