Skip to content

Commit

Permalink
Fix error cause by sync wait group
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Mar 16, 2020
1 parent 956f097 commit 70ab2aa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Cron struct {
running bool
add chan *Entry
stop chan struct{}
wg *sync.WaitGroup
wg sync.WaitGroup
}

// New instantiates new Cron instant c.
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *Cron) StopAfterJobDone() {
return
}
c.running = false
c.wg.Done()
c.wg.Wait()
c.stop <- struct{}{}
}

Expand Down Expand Up @@ -151,7 +151,8 @@ func (c *Cron) run() {
}
entry.Prev = now
entry.Next = entry.Schedule.Next(now)
go entry.Job.Run(c.wg)
c.wg.Add(1)
go entry.Job.Run(&c.wg)
}
case e := <-c.add:
e.Next = e.Schedule.Next(time.Now())
Expand All @@ -177,6 +178,5 @@ type JobFunc func()
// Run calls j()
func (j JobFunc) Run(wg *sync.WaitGroup) {
j()
wg.Add(1)
wg.Done()
}

0 comments on commit 70ab2aa

Please sign in to comment.