Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ func parallel(start, stop int, fn func(<-chan int)) {
procs = count
}

c := make(chan int, count)
for i := start; i < stop; i++ {
c <- i
}
close(c)
c := make(chan int)
done := make(chan struct{})

go func(c chan<- int) {
defer close(done)
for i := start; i < stop; i++ {
c <- i
}
close(c)
}(c)

var wg sync.WaitGroup
for i := 0; i < procs; i++ {
Expand All @@ -46,6 +51,8 @@ func parallel(start, stop int, fn func(<-chan int)) {
fn(c)
}()
}

<-done
wg.Wait()
}

Expand Down