Skip to content

Instantly share code, notes, and snippets.

@nanoninja
Last active January 28, 2016 14:11
Show Gist options
  • Save nanoninja/a98e1c00ad8eee32b8cc to your computer and use it in GitHub Desktop.
Save nanoninja/a98e1c00ad8eee32b8cc to your computer and use it in GitHub Desktop.
Channel Example
package main
import "fmt"
func main() {
ch := make(chan string)
go func(c chan string) {
ch <- "Hello Gopher"
}(ch)
fmt.Printf("%s", <-ch)
close(ch)
}
package main
import "fmt"
func main() {
ch := make(chan int)
go func() {
i := 0
for {
ch <- i
i++
}
}()
fmt.Printf("%d\n", <-ch)
fmt.Printf("%d\n", <-ch)
fmt.Printf("%d\n", <-ch)
fmt.Printf("%d\n", <-ch)
close(ch)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment