diff options
| author | Kit Langton <[email protected]> | 2026-03-25 20:19:58 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-25 20:19:58 -0400 |
| commit | f54e4b60ccb2c2ad4ebb5fdee48fe45d24af3a88 (patch) | |
| tree | fc43182aa6092e9b474694df110b6d32ed2706f6 | |
| parent | 97c15a087d34f40f4cc09c5c347fbc49b7c7af38 (diff) | |
| download | opencode-f54e4b60ccb2c2ad4ebb5fdee48fe45d24af3a88.tar.gz opencode-f54e4b60ccb2c2ad4ebb5fdee48fe45d24af3a88.zip | |
file: use Effect.cached for scan deduplication (#19164)
| -rw-r--r-- | packages/opencode/src/file/index.ts | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/packages/opencode/src/file/index.ts b/packages/opencode/src/file/index.ts index 86f7bb0dc..61f1af89d 100644 --- a/packages/opencode/src/file/index.ts +++ b/packages/opencode/src/file/index.ts @@ -2,7 +2,7 @@ import { BusEvent } from "@/bus/bus-event" import { InstanceState } from "@/effect/instance-state" import { makeRuntime } from "@/effect/run-service" import { Git } from "@/git" -import { Effect, Fiber, Layer, Scope, ServiceMap } from "effect" +import { Effect, Layer, ServiceMap } from "effect" import { formatPatch, structuredPatch } from "diff" import fs from "fs" import fuzzysort from "fuzzysort" @@ -323,7 +323,6 @@ export namespace File { interface State { cache: Entry - fiber: Fiber.Fiber<void> | undefined } export interface Interface { @@ -348,7 +347,6 @@ export namespace File { Effect.fn("File.state")(() => Effect.succeed({ cache: { files: [], dirs: [] } as Entry, - fiber: undefined as Fiber.Fiber<void> | undefined, }), ), ) @@ -406,21 +404,15 @@ export namespace File { s.cache = next }) - const scope = yield* Scope.Scope + let cachedScan = yield* Effect.cached( + scan().pipe(Effect.catchCause(() => Effect.void)), + ) const ensure = Effect.fn("File.ensure")(function* () { - const s = yield* InstanceState.get(state) - if (!s.fiber) - s.fiber = yield* scan().pipe( - Effect.catchCause(() => Effect.void), - Effect.ensuring( - Effect.sync(() => { - s.fiber = undefined - }), - ), - Effect.forkIn(scope), - ) - yield* Fiber.join(s.fiber) + yield* cachedScan + cachedScan = yield* Effect.cached( + scan().pipe(Effect.catchCause(() => Effect.void)), + ) }) const init = Effect.fn("File.init")(function* () { |
