Answer the question
In order to leave comments, you need to log in
How to run n goroutines in golang?
I need to break the start-end time interval into 10-hour intervals and run the process (from, to) method in the goroutine for each. That is, depending on the length of the start-end time interval, a different number of goroutines are launched. I do it through errgroup.WithContext(ctx)
Answer the question
In order to leave comments, you need to log in
To be honest, I didn’t quite understand what the problem is, just run the goroutines in a loop that will have the number of iterations depending on the start-end.
For example like this
//На N промежутков
step:=(end-start)/N
for n := 0; n < N; n++ {
from := start + n*step
to := from + step
group.Go(func() error{
return process(from, to)})
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question