Skip to content

Instantly share code, notes, and snippets.

@truncs
Created April 30, 2014 07:28
Show Gist options
  • Save truncs/ddcbd360e62988ce441d to your computer and use it in GitHub Desktop.
Save truncs/ddcbd360e62988ce441d to your computer and use it in GitHub Desktop.
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