Skip to content

Commit

Permalink
Merge pull request #749 from msaf1980/limits
Browse files Browse the repository at this point in the history
limiter: preallocate timeout error
  • Loading branch information
msaf1980 authored Dec 29, 2022
2 parents d04db28 + 5f495d8 commit 117040a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 3 additions & 0 deletions limiter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package limiter

import (
"context"
"errors"
)

var ErrTimeout = errors.New("timeout exceeded")

type ServerLimiter interface {
Capacity() int
Enter(ctx context.Context, s string) error
Expand Down
3 changes: 1 addition & 2 deletions limiter/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package limiter

import (
"context"
"errors"
)

// ServerLimiter provides interface to limit amount of requests
Expand Down Expand Up @@ -44,7 +43,7 @@ func (sl RealLimiter) Enter(ctx context.Context, s string) error {
case sl.m[s] <- struct{}{}:
return nil
case <-ctx.Done():
return errors.New("timeout exceeded")
return ErrTimeout
}
}

Expand Down

0 comments on commit 117040a

Please sign in to comment.