codec-util: removed newticker helper

This commit is contained in:
Trek H 2019-08-02 23:26:15 +09:30
parent 8518d931c6
commit e63b51e24f
1 changed files with 8 additions and 8 deletions

View File

@ -48,13 +48,6 @@ func init() {
close(zeroTicks) close(zeroTicks)
} }
func newTicker(d time.Duration) *time.Ticker {
if d == 0 {
return &time.Ticker{C: zeroTicks}
}
return time.NewTicker(d)
}
// Lex reads *l.bufSize bytes from src and writes them to dst every d seconds. // Lex reads *l.bufSize bytes from src and writes them to dst every d seconds.
func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, d time.Duration) error { func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, d time.Duration) error {
if l.bufSize == nil { if l.bufSize == nil {
@ -68,7 +61,14 @@ func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, d time.Duration) error {
return fmt.Errorf("invalid delay: %v", d) return fmt.Errorf("invalid delay: %v", d)
} }
ticker := newTicker(d) var ticker *time.Ticker
if d == 0 {
ticker = &time.Ticker{C: zeroTicks}
} else {
ticker = time.NewTicker(d)
defer ticker.Stop()
}
buf := make([]byte, bufSize) buf := make([]byte, bufSize)
for { for {
<-ticker.C <-ticker.C