a41f938cec
As we have seen, dependencies version can prevent the build. We should user lock versions on dependencies that we know work: * Packages are vendored * Add Godep support * Added addtional install step in readme * Fix travis build error
25 lignes
398 o
Go
25 lignes
398 o
Go
package torrent
|
|
|
|
import (
|
|
"io"
|
|
"time"
|
|
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/time/rate"
|
|
)
|
|
|
|
type rateLimitedReader struct {
|
|
l *rate.Limiter
|
|
r io.Reader
|
|
}
|
|
|
|
func (me rateLimitedReader) Read(b []byte) (n int, err error) {
|
|
if err := me.l.WaitN(context.Background(), 1); err != nil {
|
|
panic(err)
|
|
}
|
|
n, err = me.r.Read(b)
|
|
if !me.l.ReserveN(time.Now(), n-1).OK() {
|
|
panic(n - 1)
|
|
}
|
|
return
|
|
}
|