Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow functional nil limiter.Met implementation #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions concurrency-limiter/concurrency_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type ConcurrencyLimiter struct {
}

func (cl *ConcurrencyLimiter) Met() bool {
if cl == nil {
return false
}

// We should not have any ConcurrencyLimiter created with a limit of 0
// but return early if that's the case.
if cl.maxInflightRequests == 0 {
Expand Down
7 changes: 7 additions & 0 deletions concurrency-limiter/concurrency_limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
"time"
)

func Test_Met_FalseWhenNil(t *testing.T) {
var cl *ConcurrencyLimiter
if cl.Met() != false {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t know it was possible to execute methods against a nil reference. TIL

t.Fatalf("Want Met() to be false when nil, got: %t", cl.Met())
}
}

func Test_Met_FalseWhenNoLimitSet(t *testing.T) {
t.Parallel()

Expand Down