Created
April 7, 2015 16:20
-
-
Save quii/a8d00b57c7dcc4ad573b to your computer and use it in GitHub Desktop.
Simple golang channel example
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" | |
) | |
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