@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 31 lines 1.16 KB
Raw
1 import type { ThreadId } from "@t3tools/contracts";
2 import * as KeyedLock from "@t3tools/shared/KeyedLock";
3 import * as Context from "effect/Context";
4 import * as Effect from "effect/Effect";
5 import * as Layer from "effect/Layer";
6 import * as Semaphore from "effect/Semaphore";
7
8 export class ThreadCommandExecutor extends Context.Service<
9 ThreadCommandExecutor,
10 KeyedLock.KeyedLock<ThreadId> & {
11 /**
12 * One thread deletion plans and commits at a time: each decides what its deleted fork
13 * sources keep for the forks still alive. Take it before any thread lock.
14 */
15 readonly withDeletionLock: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
16 }
17 >()("t3/orchestration-v2/ThreadCommandExecutor") {}
18
19 export const make = Effect.gen(function* () {
20 const deletion = yield* Semaphore.make(1);
21 return ThreadCommandExecutor.of({
22 ...(yield* KeyedLock.make<ThreadId>()),
23 withDeletionLock: Effect.fn("ThreadCommandExecutor.withDeletionLock")(function* <A, E, R>(
24 effect: Effect.Effect<A, E, R>,
25 ) {
26 return yield* deletion.withPermit(effect);
27 }),
28 });
29 });
30
31 export const layer = Layer.effect(ThreadCommandExecutor, make);