Last active
August 23, 2017 23:21
-
-
Save davidsnt/4ea0e16de0f1cb8bb3de34d38b4f4bd8 to your computer and use it in GitHub Desktop.
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
// 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