https://github.com/iowar/throttle
Golang dynamic throttle
https://github.com/iowar/throttle
go throttle timer
Last synced: 3 months ago
JSON representation
Golang dynamic throttle
- Host: GitHub
- URL: https://github.com/iowar/throttle
- Owner: iowar
- License: gpl-3.0
- Created: 2019-04-02T20:46:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-30T16:59:48.000Z (over 4 years ago)
- Last Synced: 2025-01-23T14:31:54.266Z (5 months ago)
- Topics: go, throttle, timer
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Golang Dynamic Throttle
[](https://godoc.org/github.com/iowar/throttle)In some cases it may be necessary to change the throttle at run time.
The 'Update' channel in throttle can be used to provide triggering like time.Ticker.## Installation
```sh
$ go get -u github.com/iowar/throttle
```## Usage
Simple usage example:
```go
package mainimport (
"fmt"
"time""github.com/iowar/throttle"
)var (
kill = make(chan struct{})
)func main() {
th := throttle.NewThrottle(time.Second)
th.Start()go func() {
time.Sleep(time.Second * 6)
th.ChangeInterval(time.Second * 3)
fmt.Println("Changing interval.")
}()go func() {
time.Sleep(time.Second * 15)
th.Stop()
fmt.Println("Stopping throttle.")
}()go func() {
time.Sleep(time.Second * 24)
th.Start()
fmt.Println("Starting throttle.")
}()go func() {
time.Sleep(time.Second * 33)
kill <- struct{}{}
fmt.Println("Finish.")
}()go func() {
for {
<-th.Update
fmt.Println(time.Now())
}
}()<-kill
}```