From f72f133860fdbcb8df06885293267053291a6919 Mon Sep 17 00:00:00 2001 From: Christian Stewart Date: Tue, 23 Jul 2024 16:57:40 -0700 Subject: [PATCH] fix(refcount): wait for prev to exit in Access Signed-off-by: Christian Stewart --- refcount/refcount.go | 4 ++++ 1 file changed, 4 insertions(+) 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: }