Skip to content

Instantly share code, notes, and snippets.

@davidsnt
Last active August 23, 2017 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsnt/4ea0e16de0f1cb8bb3de34d38b4f4bd8 to your computer and use it in GitHub Desktop.
Save davidsnt/4ea0e16de0f1cb8bb3de34d38b4f4bd8 to your computer and use it in GitHub Desktop.
// Simple example of sending multiple values on a channel of a custom type
package main
import (
"fmt"
)
type num struct {
Num int
}
func sumInput(number int, c chan num) {
defer close(c)
res := new(num)
sum := number + 10
res.Num = sum
c <- *res
}
func main() {
numbers := []int{2, 4, 5, 6, 8, 9}
for _, v := range numbers {
c := make(chan num)
go sumInput(v, c)
respSum := <-c
fmt.Println(respSum.Num)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment