Skip to content

Instantly share code, notes, and snippets.

@LordRahl90
Created March 4, 2019 22:41
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 LordRahl90/1d972c508f181cc889aa9ed0756ac184 to your computer and use it in GitHub Desktop.
Save LordRahl90/1d972c508f181cc889aa9ed0756ac184 to your computer and use it in GitHub Desktop.
Producer consumer Implementation in go-lang
package main
import "fmt"
func producer(p chan int, items int) {
defer close(p)
for i := 1; i <= items; i++ {
fmt.Println("Produer Producing ", i)
p <- i
}
}
func consumer(p chan int, done chan bool) {
defer close(done)
for val := range p {
fmt.Println("Consumer Consuming Item: ", val)
}
}
func main() {
i := 100
p := make(chan int)
done := make(chan bool)
go producer(p, i)
go consumer(p, done)
<-done
fmt.Println("Everything is done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment