Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Productor-consumidor sencillo.
- // Comunidad de Go en espaƱol: https://plus.google.com/u/0/communities/105964860738231827761
- package main
- import "fmt"
- import "time"
- type Task struct {
- num int
- priority int
- index int
- }
- func main() {
- channel := make(chan int)
- go prod(channel)
- go cons(channel)
- time.Sleep(1 * time.Minute)
- }
- func prod(tocons chan int) {
- for i := 0; ; i++ {
- tocons <- i
- fmt.Println("Prod: task ", i)
- }
- }
- func cons(fromprod chan int) {
- for {
- task := <-fromprod
- time.Sleep(1000 * time.Millisecond)
- fmt.Println(" Cons: task ", task)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement