i have a chan string
which is buffered, i keep filling it with random strings until a time.Duration passes or until it gets full.
my question is should i use a ticker for that considering that its a one time task or is there a more convienient way?
here is my current way of doing it
package main
import (
"fmt"
"time"
)
func main() {
res := fillChan(time.Duration(1*time.Nanosecond), 100000)
fmt.Println(len(res))
}
func fillChan(maxDuration time.Duration, chanSize int) chan string {
c := make(chan string, chanSize)
ticker := time.NewTicker(maxDuration)
for {
select {
case <-ticker.C:
ticker.Stop()
return c
case c <- "Random message":
default:
return c
}
}
}