https://github.com/setlog/repeater
https://github.com/setlog/repeater
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/setlog/repeater
- Owner: setlog
- License: mit
- Created: 2021-08-05T15:15:13.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-18T08:47:14.000Z (almost 4 years ago)
- Last Synced: 2024-06-21T13:12:18.958Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# repeater 
Repeatedly invoke a function at a given interval until the process receives a termination signal.
Example usage:
```go
var twoWords := [2]string("Hello", "World")
type MyProcessor struct {
i int
}
func (p *MyProcessor) Process(ctx context.Context) {
fmt.Println(twoWords[p.i])
p.i = (p.i + 1) % 2
}
func (p *MyProcessor) CleanUp() {
if p.i != 0 {
fmt.Println(twoWords[1])
}
}
func main() {
callInterval := time.Second
makeFirstCallImmediately := true
repeater.New(&MyProcessor{}).Run(
context.Background(),
callInterval,
makeFirstCallImmediately)
}
```