Skip to content

Commit 32c7fe8

Browse files
committed
docs
1 parent c5f54e3 commit 32c7fe8

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Only depends on the standard library.
1313

1414
`go get github.com/linkdata/bwlimit`
1515

16+
`Ticker` must be created with `bwlimit.NewTicker()`. The zero-value `Ticker` is not supported.
17+
1618
## Example
1719

1820
```go

ticker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import (
66
)
77

88
// A Ticker synchronizes rate calculation among multiple Limiters.
9+
// Ticker values must be created with NewTicker; the zero value is not supported.
910
type Ticker struct {
1011
mu sync.Mutex
1112
ch chan struct{}
1213
}
1314

1415
var DefaultTicker *Ticker = NewTicker()
1516

17+
// NewTicker creates and starts a Ticker.
1618
func NewTicker() (ot *Ticker) {
1719
ot = &Ticker{ch: make(chan struct{})}
1820
go ot.run()

ticker_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"time"
77
)
88

9-
func TestTicker_zeroValue_NewLimiter(t *testing.T) {
10-
l := (&Ticker{}).NewLimiter(1000)
9+
func TestTicker_NewTicker_NewLimiter(t *testing.T) {
10+
l := NewTicker().NewLimiter(1000)
1111
defer l.Stop()
1212

1313
done := make(chan struct{})
@@ -19,7 +19,6 @@ func TestTicker_zeroValue_NewLimiter(t *testing.T) {
1919
select {
2020
case <-done:
2121
case <-time.After(time.Second):
22-
t.Fatal("read stalled with zero-value ticker")
22+
t.Fatal("read stalled with NewTicker")
2323
}
2424
}
25-

0 commit comments

Comments
 (0)