Исходники и презентации
This commit is contained in:
15
lessons/channels/goroutine_leak_2/main.go
Normal file
15
lessons/channels/goroutine_leak_2/main.go
Normal file
@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
// Need to show solution and describe close
|
||||
|
||||
// First-response-wins strategy
|
||||
func request() int {
|
||||
ch := make(chan int)
|
||||
for i := 0; i < 5; i++ {
|
||||
go func() {
|
||||
ch <- i // 4 goroutines will be blocked
|
||||
}()
|
||||
}
|
||||
|
||||
return <-ch
|
||||
}
|
||||
Reference in New Issue
Block a user