KO
|
EN
gitlite — search
Search
#flutter
#python
#dart
#javascript
#php
#hacktoberfest
#hacktoberfest2021
#nodejs
#deep-learning
#kubernetes
#android
#chatbot
go-timer
★ 70
Open GitHub ↗
⏰ A fast go timer with minimal goroutines.
Download README (.md)
Explore Similar Repositories
programminginpython.com
:
This repo consists code of all the programs discussed at programminginpython.com website
kattis
:
All of my solutions to Kattis archives at https://open.kattis.com
R-Data-Structures-and-Algorithms
:
R Data Structures and Algorithms, published by Packt
Stanford-University-Algorithms-Design-and-Analysis
:
Algorithms - Design and Analysis offered by Stanford University
datastruct_and_algorithms
:
python/c++实现常用算法(数据结构,搜索,排序,动态规划...)
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
go-timer
?
Download (.md)
# GO-TIMER [](https://github.com/singchia/go-xtables/actions/workflows/go.yml) [](https://opensource.org/licenses/Apache-2.0) [](https://goreportcard.com/report/github.com/singchia/go-timer/v2) ## Overview A high performance timer with minimal goroutines. ### How it works  ### Features * One goroutine runs all * Goroutine safe * Clean and simple, no third-party deps at all * High performance with timing-wheels algorithm * Minimal resources use * Managed data and handler * Customizing channel * Well tested ## Usage ### Quick Start ```golang package main import ( "log" "time" timer "github.com/singchia/go-timer/v2" ) func main() { t1 := time.Now() // new timer t := timer.NewTimer() // add a tick in 1s tick := t.Add(time.Second) // wait for it <-tick.C() // tick fired as time is up, calculate and print the elapse log.Printf("time elapsed: %fs\n", time.Now().Sub(t1).Seconds()) } ``` ### Async handler ```golang package main import ( "log" "sync" "time" timer "github.com/singchia/go-timer/v2" ) func main() { // we need a wait group since using async handler wg := sync.WaitGroup{} wg.Add(1) // new timer t := timer.NewTimer() // add a tick in 1s with current time and a async handler t.Add(time.Second, timer.WithData(time.Now()), timer.WithHandler(func(event *timer.Event) { defer wg.Done() // tick fired as time is up, calculate and print the elapse log.Printf("time elapsed: %fs\n", time.Now().Sub(event.Data.(time.Time)).Seconds()) })) wg.Wait() } ``` ### With cyclically ```golang package main import ( "log" "time" timer "github.com/singchia/go-timer/v2" ) func main() { t1 := time.Now() // new timer t := timer.NewTimer() // add cyclical tick in 1s tick := t.Add(time.Second, timer.WithCyclically()) for { // wait for it cyclically <-tick.C() t2 := time.Now() // calculate and print the elapse log.Printf("time elapsed: %fs\n", t2.Sub(t1).Seconds()) t1 = t2 } } ``` ## License © Austin Zhai, 2015-2025 Released under the [Apache License 2.0](https://github.com/singchia/go-timer/blob/master/LICENSE)