Skip to content

Commit ab7fb52

Browse files
committed
fix: add nil cb checks to refcount
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent 330f40d commit ab7fb52

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

refcount/refcount.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (r *RefCount[T]) AddRef(cb func(resolved bool, val T, err error)) *Ref[T] {
155155
r.refs[nref] = struct{}{}
156156
if len(r.refs) == 1 && !r.resolved {
157157
r.startResolveLocked()
158-
} else if r.resolved {
158+
} else if r.resolved && nref.cb != nil {
159159
nref.cb(true, r.value, r.valueErr)
160160
}
161161
r.mtx.Unlock()
@@ -255,6 +255,7 @@ func (r *RefCount[T]) ResolveWithReleased(ctx context.Context, released func())
255255
// The context will be canceled if the value is removed / changed.
256256
// Return context.Canceled if the context is canceled.
257257
// The callback may be restarted if the context is canceled and a new value is resolved.
258+
// ctx and cb cannot be nil
258259
func (r *RefCount[T]) Access(ctx context.Context, cb func(ctx context.Context, val T) error) error {
259260
var bcast broadcast.Broadcast
260261
var currVal T
@@ -311,7 +312,6 @@ func (r *RefCount[T]) Access(ctx context.Context, cb func(ctx context.Context, v
311312

312313
cbErr := func() error {
313314
defer cbCancel()
314-
315315
return cb(cbCtx, val)
316316
}()
317317

0 commit comments

Comments
 (0)