1// Copyright 2016 Google LLC 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package gensupport 6 7import ( 8 "io" 9 "time" 10) 11 12// errReader reads out of a buffer until it is empty, then returns the specified error. 13type errReader struct { 14 buf []byte 15 err error 16} 17 18func (er *errReader) Read(p []byte) (int, error) { 19 if len(er.buf) == 0 { 20 if er.err == nil { 21 return 0, io.EOF 22 } 23 return 0, er.err 24 } 25 n := copy(p, er.buf) 26 er.buf = er.buf[n:] 27 return n, nil 28} 29 30// NoPauseBackoff implements backoff with infinite 0-length pauses. 31type NoPauseBackoff struct{} 32 33func (bo *NoPauseBackoff) Pause() time.Duration { return 0 } 34 35// PauseOneSecond implements backoff with infinite 1s pauses. 36type PauseOneSecond struct{} 37 38func (bo *PauseOneSecond) Pause() time.Duration { return time.Second } 39