Skip to content

😏 golang time wheel library, which similar linux time wheel

License

Notifications You must be signed in to change notification settings

things-labs/wheel

Repository files navigation

wheel timer

golang time wheel library, which similar linux time wheel

GoDoc Go.Dev reference Build Status codecov Action Status Go Report Card Licence Tag

Feature

  • 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

Installation

Use go get.

    go get github.com/things-labs/wheel

Then import the wheel package into your own code.

    import "github.com/things-labs/wheel"

Example


[embedmd]# (_example/main.go go)

import (
	"log"
	"time"

	"github.com/things-labs/wheel"
)

func main() {
	tm := wheel.NewTimer()
	tm.WithJobFunc(func() {
		log.Println("hello world")
		wheel.Add(tm, time.Second)
	})
	wheel.Add(tm, time.Second)
	time.Sleep(time.Second * 60)
}

References


About

😏 golang time wheel library, which similar linux time wheel

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published