Skip to content

Instantly share code, notes, and snippets.

@blacknon
Created August 14, 2018 10:09
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 blacknon/4467051703321bbce3ae9680814fc8fc to your computer and use it in GitHub Desktop.
Save blacknon/4467051703321bbce3ae9680814fc8fc to your computer and use it in GitHub Desktop.
channelで文字列を送信するサンプル
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