- job default process in a goroutine,so the job do not take too long. if you have long time job,please use
WithGoroutine
- you can define every timer use goroutine.
- scan timeout's timer time complexity O(1)
- not limited max timeout
Use go get.
go get github.com/things-labs/timing
Then import the timing package into your own code.
import "github.com/things-labs/timing"
import (
"log"
"time"
"github.com/things-labs/timing"
)
func main() {
base := timing.New().Run()
tm := timing.NewTimer()
tm.WithJobFunc(func() {
log.Println("hello 1")
base.Add(tm, time.Second)
})
tm1 := timing.NewTimer()
tm1.WithJobFunc(func() {
log.Println("hello 2")
base.Add(tm1, time.Second * 2)
})
base.Add(tm, time.Second * 1)
base.Add(tm1, time.Second * 2)
time.Sleep(time.Second * 60)
}