From 5db1c008a9d877e0fd02ded6f261e3c964dd2559 Mon Sep 17 00:00:00 2001 From: Cyril David Date: Wed, 27 Jan 2021 23:15:51 -0800 Subject: [PATCH] Docs on decorator --- internal/auth0/actions/actions.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/auth0/actions/actions.go b/internal/auth0/actions/actions.go index 0a61e9dfd..4564a3ff6 100644 --- a/internal/auth0/actions/actions.go +++ b/internal/auth0/actions/actions.go @@ -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, @@ -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: