mirror of
https://github.com/pocketbase/pocketbase.git
synced 2024-11-25 01:16:21 +02:00
added done channel for the cron ticker
This commit is contained in:
parent
309c4fe6fe
commit
98ba003921
@ -27,6 +27,7 @@ type Cron struct {
|
||||
startTimer *time.Timer
|
||||
jobs map[string]*job
|
||||
interval time.Duration
|
||||
tickerDone chan bool
|
||||
|
||||
sync.RWMutex
|
||||
}
|
||||
@ -41,6 +42,7 @@ func New() *Cron {
|
||||
interval: 1 * time.Minute,
|
||||
timezone: time.UTC,
|
||||
jobs: map[string]*job{},
|
||||
tickerDone: make(chan bool),
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,6 +144,7 @@ func (c *Cron) Stop() {
|
||||
return // already stopped
|
||||
}
|
||||
|
||||
c.tickerDone <- true
|
||||
c.ticker.Stop()
|
||||
c.ticker = nil
|
||||
}
|
||||
@ -168,9 +171,14 @@ func (c *Cron) Start() {
|
||||
|
||||
// run after each tick
|
||||
go func() {
|
||||
for t := range c.ticker.C {
|
||||
for {
|
||||
select {
|
||||
case <-c.tickerDone:
|
||||
return
|
||||
case t := <-c.ticker.C:
|
||||
c.runDue(t)
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
c.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user