Skip to content

Commit

Permalink
add Limiter.Wait() example
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdata committed May 15, 2024
1 parent 0a07a04 commit 92de629
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package rate_test

import (
"fmt"
"time"

"github.com/linkdata/rate"
)

func ExampleLimiter_Wait() {
var limiter rate.Limiter
var now time.Time
maxrate := int32(1000)

// This doesn't wait at all since we haven't waited for anything yet.
now = time.Now()
limiter.Wait(&maxrate)
zeroElapsed := time.Since(now)

// This waits at least 1ms.
maxrate = 1000
now = time.Now()
limiter.Wait(&maxrate)
someElapsed := time.Since(now)

fmt.Println(zeroElapsed < someElapsed, someElapsed >= time.Millisecond)
// Output:
// true true
}

0 comments on commit 92de629

Please sign in to comment.