9 "golang.org/x/time/rate"
12 type rateLimitedReader struct {
16 // This is the time of the last Read's reservation.
20 func (me *rateLimitedReader) Read(b []byte) (n int, err error) {
21 const oldStyle = false // Retained for future reference.
23 // Wait until we can read at all.
24 if err := me.l.WaitN(context.Background(), 1); err != nil {
27 // Limit the read to within the burst.
28 if me.l.Limit() != rate.Inf && len(b) > me.l.Burst() {
35 if !me.l.ReserveN(now, n-1).OK() {
36 panic(fmt.Sprintf("burst exceeded?: %d", n-1))
39 // Limit the read to within the burst.
40 if me.l.Limit() != rate.Inf && len(b) > me.l.Burst() {
45 r := me.l.ReserveN(now, n)