Skip to content

Commit d4d2f01

Browse files
committed
fix: return idle callback release function
Signed-off-by: Christian Stewart <[email protected]>
1 parent b4841be commit d4d2f01

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

bus/multi.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ func ExecCollectValues[T directive.Value](
208208
//
209209
// errorCb can be nil.
210210
//
211-
// Returns the directive instance and reference for cleanup. If err != nil, ref == nil.
211+
// Returns the directive instance and function for cleanup. If err != nil, ref == nil.
212212
func ExecCollectValuesWatch[T directive.Value](
213213
ctx context.Context,
214214
bus Bus,
215215
dir directive.Directive,
216216
waitIdle bool,
217217
callback func(resErr []error, vals []T) error,
218218
errorCb func(err error),
219-
) (directive.Instance, directive.Reference, error) {
219+
) (directive.Instance, func(), error) {
220220
// bcast guards these variables
221221
var bcast broadcast.Broadcast
222222

@@ -291,7 +291,7 @@ func ExecCollectValuesWatch[T directive.Value](
291291
return nil, nil, err
292292
}
293293

294-
defer di.AddIdleCallback(func(isIdle bool, errs []error) {
294+
relIdleCallback := di.AddIdleCallback(func(isIdle bool, errs []error) {
295295
bcast.HoldLock(func(broadcast func(), getWaitCh func() <-chan struct{}) {
296296
wasIdle := idle
297297
idle = isIdle
@@ -311,10 +311,12 @@ func ExecCollectValuesWatch[T directive.Value](
311311
broadcast()
312312
}
313313
})
314-
})()
314+
})
315315

316316
// Goroutine to handle callbacks
317317
go func() {
318+
defer relIdleCallback()
319+
318320
for {
319321
var currVals []T
320322
var currErr []error
@@ -355,5 +357,8 @@ func ExecCollectValuesWatch[T directive.Value](
355357
}
356358
}()
357359

358-
return di, ref, nil
360+
return di, func() {
361+
relIdleCallback()
362+
ref.Release()
363+
}, nil
359364
}

0 commit comments

Comments
 (0)