Finish code
This commit is contained in:
@@ -7,8 +7,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const rateLimit = time.Second * 3 // a call each 3 second
|
||||
|
||||
// Client is an interface that calls something with a payload.
|
||||
type Client interface {
|
||||
Call(*Payload)
|
||||
@@ -28,7 +26,7 @@ func CallFunction(ctx context.Context, client Client, payload *Payload, throttle
|
||||
client.Call(payload)
|
||||
}
|
||||
|
||||
func CreateThrottle(ctx context.Context, burstLimit int) <-chan time.Time {
|
||||
func CreateThrottle(ctx context.Context, burstLimit int, rateLimit time.Duration) <-chan time.Time {
|
||||
throttle := make(chan time.Time, burstLimit)
|
||||
for i := 0; i < burstLimit; i++ {
|
||||
throttle <- time.Now()
|
||||
@@ -50,7 +48,6 @@ func CreateThrottle(ctx context.Context, burstLimit int) <-chan time.Time {
|
||||
}
|
||||
default:
|
||||
{
|
||||
fmt.Println("Dropping bucket")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user