@@ -10,16 +10,19 @@ import sun.misc.Signal
1010import java .util .concurrent .atomic .AtomicReference
1111import scala .concurrent .Await
1212import scala .concurrent .duration .Duration
13- import scala .util .{Failure , Success , Using }
13+ import scala .util .{Failure , Success }
1414
1515private [daemon] object BspMode {
1616 type RunBootstrap =
1717 (String , Option [RunnerLauncherState ], SystemStreams , Boolean ) => RunnerLauncherState
1818
19- type BootstrapBridge = [T ] => (
20- String ,
21- (Seq [EvaluatorApi ], Seq [Watchable ], Option [String ]) => T
22- ) => T
19+ // The bridge returns the bootstrap attempt's evaluators, watched set, errorOpt,
20+ // and an AutoCloseable that releases the underlying RunnerLauncherState. The
21+ // caller (MillBuildServer) owns the closeable and decides whether to release it
22+ // immediately (broken attempt) or retain it across requests (successful attempt
23+ // serving as fallback during a future broken attempt).
24+ type BootstrapBridge =
25+ String => (Seq [EvaluatorApi ], Seq [Watchable ], Option [String ], AutoCloseable )
2326
2427 def run (
2528 streams : SystemStreams ,
@@ -33,15 +36,12 @@ private[daemon] object BspMode {
3336
3437 val bspPrevState = new AtomicReference [Option [RunnerLauncherState ]](None )
3538
36- val bootstrapBridge : BootstrapBridge = [T ] =>
37- (activeCommandMessage, body) =>
38- Using .resource(
39- runMillBootstrap(activeCommandMessage, bspPrevState.get(), streams, true )
40- ) { runnerState =>
41- if (runnerState.errorOpt.isEmpty && runnerState.finalFrame.isDefined)
42- bspPrevState.set(Some (runnerState))
43- body(runnerState.allEvaluators, runnerState.watched, runnerState.errorOpt)
44- }
39+ val bootstrapBridge : BootstrapBridge = activeCommandMessage => {
40+ val newState = runMillBootstrap(activeCommandMessage, bspPrevState.get(), streams, true )
41+ if (newState.errorOpt.isEmpty && newState.finalFrame.isDefined)
42+ bspPrevState.set(Some (newState))
43+ (newState.allEvaluators, newState.watched, newState.errorOpt, newState)
44+ }
4545
4646 val (bspServerHandle, _) = startBspServer(bootstrapBridge)
4747
0 commit comments