Created
May 31, 2017 16:55
-
-
Save filinvadim/bbfbca1ead0ca22d13e6e0e3e113dfa9 to your computer and use it in GitHub Desktop.
Go channels using example
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
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