Skip to content

Instantly share code, notes, and snippets.

@suncle1993
Created August 30, 2018 07:43
Show Gist options
  • Save suncle1993/047accb54cd12807eb7d11c48e355cb7 to your computer and use it in GitHub Desktop.
Save suncle1993/047accb54cd12807eb7d11c48e355cb7 to your computer and use it in GitHub Desktop.
go csp channel print_server
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan string)
go print(c)
time.Sleep(1 * time.Second)
fmt.Println("main function: start writing msg")
c <- "hello"
var input string
fmt.Scanln(&input)
}
func print(c <-chan string) {
fmt.Println("print function: start reading")
fmt.Println("print function: reading: " + <-c)
time.Sleep(1 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment