Created
February 23, 2023 18:56
-
-
Save marcos-inja/ec99d6acf6c16cade23ef25cfb612b39 to your computer and use it in GitHub Desktop.
Implementing a pool in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
func main() { | |
var worker []int | |
for i := 0; i < 1000; i++ { | |
worker = append(worker, i) | |
fmt.Println(worker) | |
if len(worker) == 10 { | |
poolWorker(worker) | |
worker = []int{} | |
} | |
} | |
} | |
func poolWorker(worker []int) { | |
fmt.Println("Pool Worker") | |
var wg sync.WaitGroup | |
wg.Add(10) | |
for i := 0; i < 10; i++ { | |
go runnigManyTimes(&wg, worker[i]) | |
} | |
wg.Wait() | |
} | |
func runnigManyTimes(wg *sync.WaitGroup, i int) { | |
defer wg.Done() | |
fmt.Println("Running many times ", i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment