forked from TrueCloudLab/rclone
pacer: make sleep get-able and set-able
This commit is contained in:
parent
cbebefebc4
commit
9290004bb8
2 changed files with 29 additions and 0 deletions
|
@ -76,6 +76,21 @@ func New() *Pacer {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSleep sets the current sleep time
|
||||||
|
func (p *Pacer) SetSleep(t time.Duration) *Pacer {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
p.sleepTime = t
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSleep gets the current sleep time
|
||||||
|
func (p *Pacer) GetSleep() time.Duration {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
return p.sleepTime
|
||||||
|
}
|
||||||
|
|
||||||
// SetMinSleep sets the minimum sleep time for the pacer
|
// SetMinSleep sets the minimum sleep time for the pacer
|
||||||
func (p *Pacer) SetMinSleep(t time.Duration) *Pacer {
|
func (p *Pacer) SetMinSleep(t time.Duration) *Pacer {
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
|
|
|
@ -51,6 +51,20 @@ func TestNew(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetSleep(t *testing.T) {
|
||||||
|
p := New().SetSleep(2 * time.Millisecond)
|
||||||
|
if p.sleepTime != 2*time.Millisecond {
|
||||||
|
t.Errorf("didn't set")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetSleep(t *testing.T) {
|
||||||
|
p := New().SetSleep(2 * time.Millisecond)
|
||||||
|
if p.GetSleep() != 2*time.Millisecond {
|
||||||
|
t.Errorf("didn't get")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSetMinSleep(t *testing.T) {
|
func TestSetMinSleep(t *testing.T) {
|
||||||
p := New().SetMinSleep(1 * time.Millisecond)
|
p := New().SetMinSleep(1 * time.Millisecond)
|
||||||
if p.minSleep != 1*time.Millisecond {
|
if p.minSleep != 1*time.Millisecond {
|
||||||
|
|
Loading…
Reference in a new issue