30 lines
452 B
Go
30 lines
452 B
Go
|
package limiter
|
||
|
|
||
|
import (
|
||
|
"amocrm/pkg/amoClient"
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func Test_Limiter(t *testing.T) {
|
||
|
ctx := context.Background()
|
||
|
rateLimiter := amoClient.NewRateLimiter(ctx, 6, 1500*time.Millisecond)
|
||
|
|
||
|
go func() {
|
||
|
count := 1
|
||
|
for {
|
||
|
if rateLimiter.Check() {
|
||
|
fmt.Println("GO", count)
|
||
|
count++
|
||
|
continue
|
||
|
}
|
||
|
fmt.Println("SLEEP")
|
||
|
time.Sleep(1500 * time.Millisecond)
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
time.Sleep(20 * time.Second)
|
||
|
}
|