Created
December 8, 2016 17:31
-
-
Save vbauerster/db3c6bec96853f9adac8bd3f1d2b1124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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