Skip to content

Instantly share code, notes, and snippets.

@benlemasurier
Created March 3, 2014 22:31
Show Gist options
  • Save benlemasurier/9336022 to your computer and use it in GitHub Desktop.
Save benlemasurier/9336022 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
"time"
)
func main() {
const n = 100
finish := make(chan bool)
var done sync.WaitGroup
for i := 0; i < n; i++ {
done.Add(1)
go func() {
select {
case <-time.After(1 * time.Hour):
case <-finish:
}
done.Done()
}()
}
t0 := time.Now()
close(finish) // closing finish makes it ready to receive
done.Wait() // wait for all goroutines to stop
fmt.Printf("Waited %v for %d goroutines to stop\n", time.Since(t0), n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment