Go implementation of Kafka's Hierarchical Timing Wheels.
- Unlimited hierarchical wheel.
insert
,delete
,scan
task almost O(1).- Different from the time wheel of Linux, it has no maximum time limit.
- Support millions of tasks.
timed
is a globaltimer
instance, that tick is 1ms. wheel size is 512, use ants goroutine pool.
Use go get.
go get github.com/thinkgos/timer
Then import the package into your own code.
import "github.com/thinkgos/timer"
use global timer
instance.
package main
import (
"fmt"
"sync"
"time"
"github.com/thinkgos/timer/timed"
)
func main() {
var wg sync.WaitGroup
for i := 0; i < 1000; i++ {
wg.Add(1)
index := i
_, _ = timed.AfterFunc(time.Duration(i)*100*time.Millisecond, func() {
fmt.Printf("%s: timer task %d is executed, remain task: %d\n", time.Now().String(), index, timed.TaskCounter())
wg.Done()
})
}
wg.Wait()
}
This project is under MIT License. See the LICENSE file for the full license text.