@@ -51,7 +51,6 @@ const (
51
51
type API struct {
52
52
ctx context.Context
53
53
cancel context.CancelFunc
54
- initialized chan struct {}
55
54
watcherDone chan struct {}
56
55
updaterDone chan struct {}
57
56
initialUpdateDone chan struct {} // Closed after first update in updaterLoop.
@@ -266,7 +265,6 @@ func NewAPI(logger slog.Logger, options ...Option) *API {
266
265
api := & API {
267
266
ctx : ctx ,
268
267
cancel : cancel ,
269
- initialized : make (chan struct {}),
270
268
watcherDone : make (chan struct {}),
271
269
updaterDone : make (chan struct {}),
272
270
initialUpdateDone : make (chan struct {}),
@@ -317,24 +315,19 @@ func NewAPI(logger slog.Logger, options ...Option) *API {
317
315
api .subAgentClient .Store (& c )
318
316
}
319
317
320
- go func () {
321
- select {
322
- case <- api .ctx .Done ():
323
- break
324
- case <- api .initialized :
325
- go api .watcherLoop ()
326
- go api .updaterLoop ()
327
- }
328
- }()
329
-
330
318
return api
331
319
}
332
320
321
+ // Init applies a final set of options to the API and then
322
+ // begins the watcherLoop and updaterLoop. This function
323
+ // must only be called once.
333
324
func (api * API ) Init (opts ... Option ) {
334
325
for _ , opt := range opts {
335
326
opt (api )
336
327
}
337
- close (api .initialized )
328
+
329
+ go api .watcherLoop ()
330
+ go api .updaterLoop ()
338
331
}
339
332
340
333
func (api * API ) watcherLoop () {
@@ -1605,8 +1598,6 @@ func (api *API) Close() error {
1605
1598
api .logger .Debug (api .ctx , "closing API" )
1606
1599
api .closed = true
1607
1600
1608
- close (api .initialized )
1609
-
1610
1601
// Stop all running subagent processes and clean up.
1611
1602
subAgentIDs := make ([]uuid.UUID , 0 , len (api .injectedSubAgentProcs ))
1612
1603
for workspaceFolder , proc := range api .injectedSubAgentProcs {
0 commit comments