https://github.com/mmadfox/go-ticker
Abstraction over the standard golang ticker with hook support
https://github.com/mmadfox/go-ticker
golang ticker
Last synced: 5 months ago
JSON representation
Abstraction over the standard golang ticker with hook support
- Host: GitHub
- URL: https://github.com/mmadfox/go-ticker
- Owner: mmadfox
- License: mit
- Created: 2022-01-03T08:30:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-03T14:39:12.000Z (over 3 years ago)
- Last Synced: 2025-01-09T19:49:26.052Z (6 months ago)
- Topics: golang, 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
# go-ticker
```go
package mainimport (
"context"
"fmt"
"github.com/mmadfox/go-ticker"
"time"
)const oneMinute = time.Minute
func main() {
tick, err := ticker.Every(oneMinute, ticker.WaitNextLoop())
if err != nil {
panic(err)
}
ctx := context.Background()
tick.Handle(new(myHandler))
tick.Start(ctx)
<-time.After(15 * time.Minute)
tick.Stop()
}type myHandler struct {
}func (h *myHandler) Handle(_ context.Context, tick, timePoint time.Time) {
fmt.Printf("handle time:%s, tick:%s\n", timePoint, tick)
}func (h *myHandler) BeforeStart(_ context.Context) {
fmt.Println("beforeStart")
}func (h *myHandler) Tick(_ context.Context, tick time.Time, next bool) {
fmt.Println("tick", tick, next)
}func (h *myHandler) AfterStop(_ context.Context) {
fmt.Println("afterStop")
}
```