Skip to content

Commit

Permalink
Docs on decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx committed Jan 28, 2021
1 parent d52984b commit 5db1c00
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/auth0/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"gopkg.in/auth0.v5/management"
)

// NewSampledExecutionAPI creates a decorated ActionExecutionAPI which
// implements a leaky bucket based on the given interval.
func NewSampledExecutionAPI(api auth0.ActionExecutionAPI, interval time.Duration) auth0.ActionExecutionAPI {
return &sampledExecutionAPI{
api: api,
Expand All @@ -25,8 +27,11 @@ type sampledExecutionAPI struct {
timer *time.Timer
}

// errRateLimited is returned whenever the leaky bucket isn't ready to drip.
var errRateLimited = errors.New("actions: rate limited")

// Read checks if the leaky bucket is ready to drip: if not, then an
// errRateLimited is returned.
func (a *sampledExecutionAPI) Read(id string) (*management.ActionExecution, error) {
select {
case <-a.timer.C:
Expand Down

0 comments on commit 5db1c00

Please sign in to comment.