@@ -40,6 +40,7 @@ import {
4040 ProviderInstanceId ,
4141} from "@t3tools/contracts" ;
4242import { makeKeyedCoalescingWorker } from "@t3tools/shared/KeyedCoalescingWorker" ;
43+ import * as KeyedLock from "@t3tools/shared/KeyedLock" ;
4344import { HostProcessArchitecture , HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
4445import { mergePathEntries } from "@t3tools/shared/shell" ;
4546
@@ -58,7 +59,6 @@ import * as Option from "effect/Option";
5859import * as Path from "effect/Path" ;
5960import * as Schema from "effect/Schema" ;
6061import * as Scope from "effect/Scope" ;
61- import * as Semaphore from "effect/Semaphore" ;
6262import * as SynchronizedRef from "effect/SynchronizedRef" ;
6363
6464import * as ServerConfig from "../config.ts" ;
@@ -1569,7 +1569,7 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
15691569 sessions : new Map ( ) ,
15701570 killFibers : new Map ( ) ,
15711571 } ) ;
1572- const threadLocksRef = yield * SynchronizedRef . make ( new Map < string , Semaphore . Semaphore > ( ) ) ;
1572+ const threadLocks = yield * KeyedLock . make < string > ( ) ;
15731573 const terminalEventListeners = new Set < ( event : TerminalEvent ) => Effect . Effect < void > > ( ) ;
15741574 const workerScope = yield * Scope . make ( "sequential" ) ;
15751575 yield * Effect . addFinalizer ( ( ) => Scope . close ( workerScope , Exit . void ) ) ;
@@ -1598,29 +1598,10 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
15981598 f : ( state : TerminalManagerState ) => readonly [ A , TerminalManagerState ] ,
15991599 ) => SynchronizedRef . modify ( managerStateRef , f ) ;
16001600
1601- const getThreadSemaphore = ( threadId : string ) =>
1602- SynchronizedRef . modifyEffect ( threadLocksRef , ( current ) => {
1603- const existing : Option . Option < Semaphore . Semaphore > = Option . fromNullishOr (
1604- current . get ( threadId ) ,
1605- ) ;
1606- return Option . match ( existing , {
1607- onNone : ( ) =>
1608- Semaphore . make ( 1 ) . pipe (
1609- Effect . map ( ( semaphore ) => {
1610- const next = new Map ( current ) ;
1611- next . set ( threadId , semaphore ) ;
1612- return [ semaphore , next ] as const ;
1613- } ) ,
1614- ) ,
1615- onSome : ( semaphore ) => Effect . succeed ( [ semaphore , current ] as const ) ,
1616- } ) ;
1617- } ) ;
1618-
16191601 const withThreadLock = < A , E , R > (
16201602 threadId : string ,
16211603 effect : Effect . Effect < A , E , R > ,
1622- ) : Effect . Effect < A , E , R > =>
1623- Effect . flatMap ( getThreadSemaphore ( threadId ) , ( semaphore ) => semaphore . withPermit ( effect ) ) ;
1604+ ) : Effect . Effect < A , E , R > => threadLocks . withLock ( threadId , effect ) ;
16241605
16251606 const clearKillFiber = Effect . fn ( "terminal.clearKillFiber" ) ( function * (
16261607 process : PtyAdapter . PtyProcess | null ,
0 commit comments