Created
August 14, 2018 10:09
-
-
Save blacknon/4467051703321bbce3ae9680814fc8fc to your computer and use it in GitHub Desktop.
channelで文字列を送信するサンプル
This file contains hidden or 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 ( | |
"log" | |
"strconv" | |
"time" | |
) | |
func logSender(resc chan string) { | |
for i := 0; i < 10; i++ { | |
time.Sleep(1 * time.Second) | |
resc <- strconv.Itoa(i) + "_abc" | |
} | |
close(resc) | |
} | |
func main() { | |
resc := make(chan string, 1) | |
go func(resc chan string) { | |
logSender(resc) | |
}(resc) | |
for i := range resc { | |
log.Println("log:", i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment