Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save filinvadim/bbfbca1ead0ca22d13e6e0e3e113dfa9 to your computer and use it in GitHub Desktop.
Save filinvadim/bbfbca1ead0ca22d13e6e0e3e113dfa9 to your computer and use it in GitHub Desktop.
Go channels using example
func multiparseText() string {
collectedTexts := ""
ch := make(chan string, parseThreadsNum)
defer close(ch)
for i := 0; i < parseThreadsNum; i++ {
go parseText(&ch)
}
for {
unreadData := len(ch)
if unreadData == parseThreadsNum {
for i := unreadData; i > 0; i-- {
collectedTexts += <-ch
}
break
}
runtime.Gosched()
}
return collectedTexts
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment