Skip to content

Commit

Permalink
refactor(limiter): make blocking/non-blocking code more similar
Browse files Browse the repository at this point in the history
  • Loading branch information
costela committed Oct 12, 2023
1 parent 1c60646 commit 78e4bfe
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ func newLimiter(origFactory observerFactory, limit int64, block bool) observerFa
}
}
return func(ctx context.Context) (observer, error) {
if sem.TryAcquire(1) {
return wrappedFactory(ctx)
} else {
if !sem.TryAcquire(1) {
return nil, ErrConcurrencyLimitReached
}
return wrappedFactory(ctx)
}
}

0 comments on commit 78e4bfe

Please sign in to comment.