Created
April 30, 2014 07:28
-
-
Save truncs/ddcbd360e62988ce441d to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
iterations := 10 | |
myChannel := make(chan int) | |
go producer(myChannel, iterations) | |
go consumer(myChannel, iterations) | |
time.Sleep(500 * time.Millisecond) | |
} | |
func producer(myChannel chan int, iterations int) { | |
for i:= 1; i <= iterations; i++ { | |
fmt.Println("Sending: ", i) | |
myChannel <- i | |
} | |
} | |
func consumer(myChannel chan int, iterations int) { | |
for i:= 1; i <= iterations; i++ { | |
recVal := <-myChannel | |
fmt.Println("Received: ", recVal) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment