Open pravj opened 7 years ago
Using channel based synchronization in Add method prevents the data races when the cron instance is running.
channel
Add
data races
Although, it can't stop them when the cron instance is inactive.
package main import ( "fmt" "time" "github.com/roylee0704/gron" ) func main() { blocker := make(chan int) g := gron.New() g.AddFunc(gron.Every(4*time.Second), func() { fmt.Println("J-1/4") }) g.AddFunc(gron.Every(3*time.Second), func() { fmt.Println("J-2/3") }) // this will access (write) the shared state 'entries' concurrently go func() { g.AddFunc(gron.Every(2*time.Second), func() { fmt.Println("J-3/2") }) }() g.Start() <-blocker }
Running this with Golang's Race Detector will report the data race.
Race Detector
$ go run -race main.go
I propose to use Mutex for this particular case.
Mutex
cc @roylee0704
Using
channel
based synchronization inAdd
method prevents thedata races
when the cron instance is running.Although, it can't stop them when the cron instance is inactive.
Running this with Golang's
Race Detector
will report the data race.I propose to use
Mutex
for this particular case.cc @roylee0704