Created
August 31, 2020 21:27
-
-
Save mikeplavsky/27bff1c4a62a541fd0d191a5d1fbfa70 to your computer and use it in GitHub Desktop.
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
func runner(tasks []int, workers int, f func(int) int) { | |
in, out := make(chan int), make(chan int) | |
for i := 0; i < workers; i++ { | |
go func() { | |
for { | |
out <- f(<-in) | |
} | |
}() | |
} | |
for _, v := range tasks { | |
in <- v | |
} | |
var res []int | |
for i := 0; i < len(tasks); i++ { | |
res = append(res, <-out) | |
} | |
fmt.Println("Done!\n", res) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment