Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeConcurrencyChunks ¶
MakeConcurrencyChunks will return chunks of ids. The basic use case is to fill in a list concurrently in a concise way. Indexes will go (no pun intended) from 0 to maxLength-1 and be broken down between chunks of concurrency or less size.
Example ¶
numbersToHalves := []int{4, 10, 30, 200, 3090} halvedNumbers := make([]int, 5) concurrentIdsChunks := MakeConcurrencyChunks(5, 2) // iterate over chunks with their own waitgroup synchronously for _, cChunk := range concurrentIdsChunks { var wg sync.WaitGroup wg.Add(len(cChunk)) // for each chunk conrrent task pop a worker and perform task for _, taskId := range cChunk { go func(i int) { halvedNumbers[i] = numbersToHalves[i] >> 1 wg.Done() }(taskId) } wg.Wait() } fmt.Println(halvedNumbers)
Output: {2, 5, 15, 100, 1545}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.