Skip to content

Instantly share code, notes, and snippets.

@emretanriverdi
Created January 17, 2021 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emretanriverdi/af8befc07343dfacd46d5652cd959505 to your computer and use it in GitHub Desktop.
Save emretanriverdi/af8befc07343dfacd46d5652cd959505 to your computer and use it in GitHub Desktop.
channel-deadlock-fixed.go
func readAndSend() {
c := make(chan User)
go readFromCouchbase("123", c)
for user := range c {
sendToKafka(user)
}
}
func readFromCouchbase(key string, c chan User) {
time.Sleep(5 * time.Millisecond)
fmt.Println("# read from Couchbase for key -> " + key)
c <- User{Id: 123, Name: "Emre"}
close(c) // look here!!
}
func sendToKafka(user User) {
fmt.Println("# sending to Kafka for username -> " + user.Name)
time.Sleep(5 * time.Millisecond)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment