Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Last active April 14, 2016 16:18
Show Gist options
  • Save md2perpe/f2f5d3b91f63b403ef70bd5d5295e968 to your computer and use it in GitHub Desktop.
Save md2perpe/f2f5d3b91f63b403ef70bd5d5295e968 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type H struct { seq int }
type O struct { seq int }
type H2O struct {
h1, h2 H
o O
}
func (h2o H2O)String() string {
return fmt.Sprintf("H(%d)O(%d)H(%d)", h2o.h1.seq, h2o.o.seq, h2o.h2.seq)
}
func main() {
chH := make(chan H, 10)
chO := make(chan O, 10)
go func() {
for i:=1; ; i++ {
chH <- H{i}
}
}()
go func() {
for i:=1; ; i++ {
chO <- O{i}
}
}()
chH2O := make(chan H2O, 10)
go func() {
for {
h1 := <-chH
h2 := <-chH
o := <-chO
chH2O <- H2O{h1, h2, o}
}
}()
for i:=0; i<5; i++ {
h2o := <-chH2O
fmt.Println(h2o)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment