golang time wheel library, which similar linux time wheel
- Five-level time wheel: main level and four levels.
- insert,delete,modify,scan item time complexity O(1).
- the default time granularity is 1ms.
- The maximum time is limited by the accuracy of the time base. The time granularity is 1ms, and the maximum time can be 49.71 days. so the maximum time is 49.71 days * (granularity/1ms)
- There is the internal wheel timer base with granularity 1ms,it lazies init internal until you first used.
- NOTE:do not use Time consuming task @ timer callback function,you can with
WithGoroutine
Use go get.
go get github.com/thinkgos/wheel
Then import the modbus package into your own code.
import modbus "github.com/thinkgos/wheel"
import (
"log"
"time"
"github.com/thinkgos/wheel"
)
func main() {
base := wheel.New()
base.Run()
tm := wheel.NewTimer()
tm.WithJobFunc(func() {
log.Println("hello world")
base.Add(tm, time.Second)
})
base.Add(tm, time.Second)
time.Sleep(time.Second * 60)
}