Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andy2046/tik
hierarchical timing wheel
https://github.com/andy2046/tik
ticker timer timing-wheel
Last synced: 26 days ago
JSON representation
hierarchical timing wheel
- Host: GitHub
- URL: https://github.com/andy2046/tik
- Owner: andy2046
- License: bsd-3-clause
- Created: 2020-07-04T09:13:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-17T03:23:45.000Z (about 4 years ago)
- Last Synced: 2024-11-17T22:36:27.410Z (about 1 month ago)
- Topics: ticker, timer, timing-wheel
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-extra - tik - 07-04T09:13:49Z|2020-10-17T03:23:45Z| (Utilities / Fail injection)
README
# tik
[![Documentation](https://godoc.org/github.com/andy2046/tik?status.svg)](http://godoc.org/github.com/andy2046/tik)
[![GitHub issues](https://img.shields.io/github/issues/andy2046/tik.svg)](https://github.com/andy2046/tik/issues)
[![license](https://img.shields.io/github/license/andy2046/tik.svg)](https://github.com/andy2046/tik/LICENSE)
[![Release](https://img.shields.io/github/release/andy2046/tik.svg?label=Release)](https://github.com/andy2046/tik/releases)----
## hierarchical timing wheel made easy
simplified version of [timeout](https://github.com/wahern/timeout) in Golang
for documentation, view the [API reference](./doc.md)
## Install
```
go get github.com/andy2046/tik
```## Usage
```go
package mainimport (
"sync"
"time""github.com/andy2046/tik"
)func main() {
var l sync.RWMutex
// init a new instance
tk := tik.New()
i := 0
cb := func() {
l.Lock()
i++
l.Unlock()
}
// schedule to run cb in 500ms
to := tk.Schedule(500, cb)if !to.Pending() {
panic("it should be pending")
}if to.Expired() {
panic("it should NOT be expired")
}for {
time.Sleep(100 * time.Millisecond)if tk.AnyPending() {
continue
}if tk.AnyExpired() {
continue
}break
}l.RLock()
defer l.RUnlock()if i != 1 {
panic("fail to callback", i)
}
}
```