Refactor: use chunk manager to manage resume upload in server side

This commit is contained in:
HFO4
2022-03-13 16:17:20 +08:00
parent b96019be7c
commit effbc8607e
4 changed files with 113 additions and 61 deletions

View File

@@ -0,0 +1,31 @@
package backoff
import "time"
// Backoff used for retry sleep backoff
type Backoff interface {
Next() bool
Reset()
}
// ConstantBackoff implements Backoff interface with constant sleep time
type ConstantBackoff struct {
Sleep time.Duration
Max int
tried int
}
func (c *ConstantBackoff) Next() bool {
c.tried++
if c.tried >= c.Max {
return false
}
time.Sleep(c.Sleep)
return true
}
func (c *ConstantBackoff) Reset() {
c.tried = 0
}