Created
January 15, 2020 14:22
-
-
Save ismdeep/44b56aa0e349b3e696db515c4d486905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "sync" | |
type receiver struct { | |
sync.WaitGroup | |
data chan int | |
} | |
func newReceiver() *receiver { | |
r := &receiver{ | |
data: make(chan int, 1000000), | |
} | |
r.Add(1) | |
go func(dataChan chan int) { | |
for x := range dataChan{ | |
println("recv : ", x) | |
} | |
defer r.Done() | |
}(r.data) | |
return r | |
} | |
func main() { | |
r := newReceiver() | |
for i := 0; i < 100000; i++ { | |
r.data <- i | |
} | |
close(r.data) | |
r.Wait() | |
println("Done") | |
} |
Author
ismdeep
commented
Jan 15, 2020
- https://stackoverflow.com/questions/13566065/why-my-golang-channel-raise-dead-lock-error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment