Skip to content

Instantly share code, notes, and snippets.

@vbauerster
Created December 8, 2016 17:31
Show Gist options
  • Save vbauerster/db3c6bec96853f9adac8bd3f1d2b1124 to your computer and use it in GitHub Desktop.
Save vbauerster/db3c6bec96853f9adac8bd3f1d2b1124 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func main() {
inch := make(chan int)
outch := make(chan int)
go func() {
var in <-chan int = inch
var out chan<- int
var val int
for {
select {
case out <- val:
out = nil
in = inch
case val = <-in:
out = outch
in = nil
}
}
}()
go func() {
for r := range outch {
fmt.Println("result", r)
}
}()
time.Sleep(0)
inch <- 1
inch <- 2
time.Sleep(3 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment