https://github.com/hlts2/gticker
Time ticker with immediate first tick
https://github.com/hlts2/gticker
go golang hlts2 simple ticker
Last synced: 7 months ago
JSON representation
Time ticker with immediate first tick
- Host: GitHub
- URL: https://github.com/hlts2/gticker
- Owner: hlts2
- License: mit
- Created: 2021-08-27T10:44:37.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-27T12:14:57.000Z (about 4 years ago)
- Last Synced: 2025-01-20T08:09:30.889Z (9 months ago)
- Topics: go, golang, hlts2, simple, ticker
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gticker
gticker is time ticker with immediate first tick.
The Go standard library has a really cool type – Ticker.
Tickers are used when you want to do something at a regular interval.
However, if we want to tic immediately the first time, we can cut it out to a function and call it before tic.
This package was created for the purpose of being able to handle a different approach from that implementation.## Requirement
Go 1.16
## Installation
```shell
go get github.com/hlts2/gticker
```## Example
```go
package main
import (
"fmt"
"time""github.com/hlts2/gticker"
)func main() {
ticker := gticker.NewInstantTicker(1 * time.Second)
done := make(chan bool)go func() {
for {
select {
case <-done:
return
case t := <-ticker.C():
fmt.Println("Tick at", t)
}
}
}()time.Sleep(3 * time.Second)
ticker.Stop()
done <- true
fmt.Println("Ticker stopped")
}
```## Author
[hlts2](https://github.com/hlts2)