Skip to content

Instantly share code, notes, and snippets.

@marcos-inja
Created February 23, 2023 18:56
Show Gist options
  • Save marcos-inja/ec99d6acf6c16cade23ef25cfb612b39 to your computer and use it in GitHub Desktop.
Save marcos-inja/ec99d6acf6c16cade23ef25cfb612b39 to your computer and use it in GitHub Desktop.
Implementing a pool in golang
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