Skip to content

Instantly share code, notes, and snippets.

@jrusev
Created April 8, 2017 13:31
Show Gist options
  • Save jrusev/c624120fd4acd2698eefb32302d30a8d to your computer and use it in GitHub Desktop.
Save jrusev/c624120fd4acd2698eefb32302d30a8d to your computer and use it in GitHub Desktop.

Revisions

  1. jrusev created this gist Apr 8, 2017.
    23 changes: 23 additions & 0 deletions workers.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    package main

    import "fmt"
    import "time"

    func f(in <-chan int, out chan<- int) {
    for j := range in {
    time.Sleep(time.Second)
    out <- j * 2
    }
    }

    func main() {
    in := make(chan int, 100)
    out := make(chan int, 100)
    go f(in, out)
    for j := 1; j <= 8; j++ {
    in <- j
    }
    for a := 1; a <= 8; a++ {
    fmt.Println(<-out)
    }
    }