Skip to content
Projects

About

golang timewheel similar to glang std timer

Other Projects

How these counts are measured

Measured star growth

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

go-timewheel

golang timewheel lib, similar to golang std timer

Usage

base method

init timewheel

tw, err := NewTimeWheel(1 * time.Second, 360)
if err != nil {
    panic(err)
}

tw.Start()
tw.Stop()

safe ticker

tw, _ := NewTimeWheel(1 * time.Second, 360, TickSafeMode())

use sync.Pool

tw, _ := NewTimeWheel(1 * time.Second, 360, SetSyncPool(true))

add delay task

task := tw.Add(5 * time.Second, func(){})

remove delay task

tw.Remove(task)

add cron delay task

task := tw.AddCron(5 * time.Second, func(){
    ...
})

similar to std time

similar to time.Sleep

tw.Sleep(5 * time.Second)

similar to time.After()

<- tw.After(5 * time.Second)

similar to time.NewTimer

timer :=tw.NewTimer(5 * time.Second)
<- timer.C
timer.Reset(1 * time.Second)
timer.Stop()

similar to time.NewTicker

timer :=tw.NewTicker(5 * time.Second)
<- timer.C
timer.Stop()

similar to time.AfterFunc

runner :=tw.AfterFunc(5 * time.Second, func(){})
<- runner.C
runner.Stop()

benchmark test

example/main.go

Explore related projects

Loading…