26 lines
395 B
Go
26 lines
395 B
Go
package main
|
|
|
|
import ("time"; "fmt")
|
|
|
|
func main() {
|
|
tick := time.Tick(time.Millisecond * 200)
|
|
throttle := make(chan bool, 10)
|
|
go func() {
|
|
for {
|
|
<- tick
|
|
select {
|
|
case throttle <- true:
|
|
default:
|
|
}
|
|
}
|
|
}()
|
|
time.Sleep(time.Millisecond * 1000)
|
|
for {
|
|
<- throttle
|
|
go fmt.Println("acting")
|
|
}
|
|
}
|
|
|
|
// == todo
|
|
// credit http://code.google.com/p/go-wiki/wiki/RateLimiting
|