Skip to content

cyub/hashedwheeltimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hashed Timing Wheel Timer

a timer based on Hashed Timing Wheel

Usage

type job func(timeout hashedwheeltimer.Timeout) bool

func (j job) Run(timeout hashedwheeltimer.Timeout) bool {
	return j(timeout)
}

func main() {
	hwt := hashedwheeltimer.NewHashedWheelTimer(time.Second, 16)

	fn1 := func(timeout hashedwheeltimer.Timeout) bool {
		fmt.Println(time.Now(), "job1 run")
		timeout.Timer().NewTimeout(timeout.Task(), time.Duration(timeout.Deadline()))
		return true
	}

	fn2 := func(timeout hashedwheeltimer.Timeout) bool {
		fmt.Println(time.Now(), "job2 run")
		return true
	}

	hwt.NewTimeout(job(fn1), time.Second)
	hwt.NewTimeout(job(fn2), 3*time.Second)
	time.Sleep(15 * time.Second)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages