Finish code

This commit is contained in:
2024-11-12 21:21:23 +01:00
parent 82790e260d
commit 27bed5a2b7
6 changed files with 67 additions and 71 deletions

View File

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