mirror of
https://github.com/rclone/rclone.git
synced 2024-11-30 04:15:26 +01:00
33 lines
575 B
Go
33 lines
575 B
Go
|
package odrvcookie
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"github.com/ncw/rclone/lib/rest"
|
||
|
)
|
||
|
|
||
|
// CookieRenew holds information for the renew
|
||
|
type CookieRenew struct {
|
||
|
srv *rest.Client
|
||
|
timer *time.Ticker
|
||
|
renewFn func()
|
||
|
}
|
||
|
|
||
|
// NewRenew returns and starts a CookieRenew
|
||
|
func NewRenew(interval time.Duration, renewFn func()) *CookieRenew {
|
||
|
renew := CookieRenew{
|
||
|
timer: time.NewTicker(interval),
|
||
|
renewFn: renewFn,
|
||
|
}
|
||
|
go renew.Renew()
|
||
|
return &renew
|
||
|
}
|
||
|
|
||
|
// Renew calls the renewFn for every tick
|
||
|
func (c *CookieRenew) Renew() {
|
||
|
for {
|
||
|
<-c.timer.C // wait for tick
|
||
|
c.renewFn()
|
||
|
}
|
||
|
}
|