I have the following: http://play.golang.org/p/1aaive8KQx
When I print the runtime.NumGoroutine() I get 3. Shouldn't I be getting just 1? Why?
package main
import (
"log"
"runtime"
"time"
)
func main() {
for i := 1; i <= 10; i++ {
ch := make(chan int, 10)
timeout := time.Tick(1 * time.Second)
for i := 1; i <= 10; i++ {
go func(i int) {
time.Sleep(2 * time.Second)
ch <- i
}(i)
}
for i := 1; i <= 10; i++ {
select {
case j := <-ch:
log.Println(j)
case <-timeout:
log.Println("timeout")
}
}
log.Println("Processes", runtime.NumGoroutine())
}
}