https://github.com/hslam/timer
Package timer provides functionality for measuring time. Much lower CPU overhead when using use_cgo tags during the idle period of system.
https://github.com/hslam/timer
go golang sleep ticker time timer
Last synced: about 2 months ago
JSON representation
Package timer provides functionality for measuring time. Much lower CPU overhead when using use_cgo tags during the idle period of system.
- Host: GitHub
- URL: https://github.com/hslam/timer
- Owner: hslam
- License: mit
- Created: 2019-09-22T16:47:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-19T14:59:45.000Z (over 4 years ago)
- Last Synced: 2023-07-27T18:04:44.937Z (about 2 years ago)
- Topics: go, golang, sleep, ticker, time, timer
- Language: Go
- Homepage:
- Size: 97.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timer
[](https://pkg.go.dev/github.com/hslam/timer)
[](https://github.com/hslam/timer/actions)
[](https://codecov.io/gh/hslam/timer)
[](https://goreportcard.com/report/github.com/hslam/timer)
[](https://github.com/hslam/timer/blob/master/LICENSE)Package timer provides functionality for measuring time. Much lower CPU overhead when using use_cgo tags during the idle period of system.
## Feature
* cgo/go
* Ticker
* TickFunc
* Timer
* Sleep
* After## Get started
### Install
```
go get github.com/hslam/timer
```
### Import
```
import "github.com/hslam/timer"
```
### Usage
#### Example
```go
package mainimport (
"flag"
"fmt"
"github.com/hslam/timer"
)func main() {
t := *flag.String("t", "Sleep", "use timer")
flag.Parse()
fmt.Println(timer.Tag)
switch t {
case "Ticker":
t := timer.NewTicker(timer.Millisecond)
defer t.Stop()
for range t.C {
//todo
}
case "TickFunc":
t := timer.TickFunc(timer.Millisecond, func() {
//todo
})
defer t.Stop()
select {}
case "Timer":
t := timer.NewTimer(timer.Millisecond)
defer t.Stop()
for range t.C {
t.Reset(timer.Millisecond)
//todo
}
case "Sleep":
for {
timer.Sleep(timer.Millisecond)
//todo
}
case "After":
for {
select {
case <-timer.After(timer.Millisecond):
//todo
}
}
default:
fmt.Println("use Ticker, TickFunc, Timer, Sleep or After")
}
}
```### Build
#### go
```
go build
```
#### cgo
```
go build -tags=use_cgo
```### License
This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)### Author
timer was written by Meng Huang.