Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func main() {
- // your queue of jobs
- q := make(chan int)
- // done channel takes the result of the job
- done := make(chan bool)
- numberOfWorkers := 2
- for i := 0; i < numberOfWorkers; i++ {
- go worker(q, i, done)
- }
- // appends a job to the queue
- numberOfJobs := 17
- for j := 0; j < numberOfJobs; j++ {
- go func(j int) {
- q <- j
- }(j)
- }
- for c := 0; c < numberOfJobs; c++ {
- <-done
- }
- }
Add Comment
Please, Sign In to add comment