Correct context
This commit is contained in:
@@ -24,8 +24,8 @@ type Payload struct {
|
||||
// CallFunction allows burst rate limiting client calls with the
|
||||
// payloads.
|
||||
func CallFunction(ctx context.Context, client Client, payload *Payload, throttle <-chan time.Time) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
//ctx, cancel := context.WithCancel(ctx)
|
||||
// defer cancel()
|
||||
|
||||
<-throttle // rate limit our client calls
|
||||
client.Call(payload)
|
||||
@@ -43,11 +43,18 @@ func CreateThrottle(ctx context.Context, burstLimit int) <-chan time.Time {
|
||||
for t := range ticker.C {
|
||||
select {
|
||||
case throttle <- t:
|
||||
{
|
||||
fmt.Println("Add bucket to throttle")
|
||||
}
|
||||
case <-ctx.Done():
|
||||
{
|
||||
fmt.Println("Ticker done")
|
||||
return // exit goroutine when surrounding function returns
|
||||
}
|
||||
default:
|
||||
{
|
||||
fmt.Println("Dropping bucket")
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user