Correct context

This commit is contained in:
2024-11-11 21:34:30 +01:00
parent b915af2ab4
commit ac5837e26a
2 changed files with 29 additions and 7 deletions

View File

@@ -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")
}
}
}
}()