Created
August 30, 2018 07:43
-
-
Save suncle1993/047accb54cd12807eb7d11c48e355cb7 to your computer and use it in GitHub Desktop.
go csp channel print_server
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 ( | |
"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