In the following code
- What happens to
goroutine1
?(at the end of program we have three goroutinegoroutine1
without any functionality) - What happens to channel?(when we make a channel in loop it release the previous channel memory? close it? or something else?)
func main() {
for i := 1; i <= 3; i += 1 {
ch := make(chan int)
// gorutine1
go func() {
time.Sleep(3 * time.Second)
ch <- i
fmt.Println("gorutine1 end")
}()
// gorutine2
go func() {
time.Sleep(1 * time.Second)
ch <- i+1000
fmt.Println("gorutine2 end")
}()
fmt.Println("loop", <-ch)
}
time.Sleep(10 * time.Second)
fmt.Println("main end")
}
Run above code here