Skip to content

Instantly share code, notes, and snippets.

@quii
Created April 7, 2015 16:20
Show Gist options
  • Save quii/a8d00b57c7dcc4ad573b to your computer and use it in GitHub Desktop.
Save quii/a8d00b57c7dcc4ad573b to your computer and use it in GitHub Desktop.
Simple golang channel example
package main
import (
"fmt"
)
type Baz struct {
Y string
}
func (b Baz) X() string {
return "burp"
}
// Interfaces cant define fields for reasons... google :p
type Foo interface {
X() string
}
func DoIt(stuff <-chan Foo) {
thing := <-stuff
fmt.Println(thing.X())
}
func main() {
c := make(chan Foo, 10) // size of 10
c <- Baz{"Foo"}
DoIt(c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment