feat: add aliyundrive driver

This commit is contained in:
Noah Hsu
2022-08-31 20:46:19 +08:00
parent 102384e170
commit 817d63597e
9 changed files with 579 additions and 0 deletions

35
pkg/cron/cron.go Normal file
View File

@ -0,0 +1,35 @@
package cron
import "time"
type Cron struct {
d time.Duration
ch chan struct{}
}
func NewCron(d time.Duration) *Cron {
return &Cron{
d: d,
ch: make(chan struct{}),
}
}
func (c *Cron) Do(f func()) {
go func() {
ticker := time.NewTicker(c.d)
defer ticker.Stop()
for {
select {
case <-ticker.C:
f()
case <-c.ch:
return
}
}
}()
}
func (c *Cron) Stop() {
c.ch <- struct{}{}
close(c.ch)
}