diff --git a/refcount/refcount.go b/refcount/refcount.go index b728cc2..8069b6e 100644 --- a/refcount/refcount.go +++ b/refcount/refcount.go @@ -358,6 +358,10 @@ func (r *RefCount[T]) Access(ctx context.Context, useCtx bool, cb func(ctx conte if prevCancel != nil { prevCancel() } + if prevWait != nil { + // wait for previous routine to exit. + <-prevWait + } return context.Canceled case <-waitCh: }