GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — opencode/packages/opencode/src/effect/instance-state.ts at dev · ngbrown/opencode Expand file tree/ Copy pathinstance-state.tsMore file actions 69 lines (55 loc) · 2.33 KB / Copy pathinstance-state.tsFile metadata and controls69 lines (55 loc) · 2.33 KB 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 import { Effect, ScopedCache, Scope } from "effect" import type { InstanceContext } from "@/project/instance-context" import { InstanceRef, WorkspaceRef } from "./instance-ref" import { registerDisposer } from "./instance-registry" import { WorkspaceContext } from "@/control-plane/workspace-context" const TypeId = "~opencode/InstanceState" export interface InstanceState<A, E = never, R = never> { readonly [TypeId]: typeof TypeId readonly cache: ScopedCache.ScopedCache<string, A, E, R> } export const context = Effect.gen(function* () { const ctx = yield* InstanceRef if (!ctx) return yield* Effect.die(new Error("InstanceRef not provided")) return ctx }) export const workspaceID = Effect.gen(function* () { return (yield* WorkspaceRef) ?? WorkspaceContext.workspaceID }) export const directory = Effect.map(context, (ctx) => ctx.directory) export const make = <A, E = never, R = never>( init: (ctx: InstanceContext) => Effect.Effect<A, E, R | Scope.Scope>, ): Effect.Effect<InstanceState<A, E, Exclude<R, Scope.Scope>>, never, R | Scope.Scope> => Effect.gen(function* () { const cache = yield* ScopedCache.make<string, A, E, R>({ capacity: Number.POSITIVE_INFINITY, lookup: () => Effect.gen(function* () { return yield* init(yield* context) }), }) const off = registerDisposer((directory) => Effect.runPromise(ScopedCache.invalidate(cache, directory))) yield* Effect.addFinalizer(() => Effect.sync(off)) return { [TypeId]: TypeId, cache, } }) export const get = <A, E, R>(self: InstanceState<A, E, R>) => Effect.gen(function* () { return yield* ScopedCache.get(self.cache, yield* directory) }) export const use = <A, E, R, B>(self: InstanceState<A, E, R>, select: (value: A) => B) => Effect.map(get(self), select) export const useEffect = <A, E, R, B, E2, R2>( self: InstanceState<A, E, R>, select: (value: A) => Effect.Effect<B, E2, R2>, ) => Effect.flatMap(get(self), select) export const has = <A, E, R>(self: InstanceState<A, E, R>) => Effect.gen(function* () { return yield* ScopedCache.has(self.cache, yield* directory) }) export const invalidate = <A, E, R>(self: InstanceState<A, E, R>) => Effect.gen(function* () { return yield* ScopedCache.invalidate(self.cache, yield* directory) }) export * as InstanceState from "./instance-state" |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |