Considering the following code block, it's expected to throw an error due to reaching a the buffer limit:
package main
import (
"fmt"
"time"
)
func main() {
burstyLimiter := make(chan time.Time, 4)
for i := 0; i < 5; i++ {
burstyLimiter <- time.Now()
fmt.Println("adding to burstyLimiter")
}
}
But when I try the exact block with the following, it blocks instead of throwing an error. I am tying to understand this behavior. Thanks for your time.
package main
import (
"fmt"
"time"
)
func main() {
requests := make(chan int, 5)
close(requests)
limiter := time.Tick(time.Millisecond * 200)
for req := range requests {
<-limiter
fmt.Println("request", req, time.Now())
}
burstyLimiter := make(chan time.Time, 4)
for i := 0; i < 5; i++ {
burstyLimiter <- time.Now()
fmt.Println("adding to burstyLimiter")
}
}