Created
December 18, 2016 05:00
-
-
Save slav/ca2ee333c29b8f76b557c9b10b371b52 to your computer and use it in GitHub Desktop.
Golang sending sending multiple values through channel
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" | |
func f(c chan func() (int, string)) { | |
c <- (func() (int, string) { return 0, "s" }) | |
} | |
func main() { | |
c := make(chan func() (int, string)) | |
go f(c) | |
y, z := (<-c)() | |
fmt.Println(y) | |
fmt.Println(z) | |
} |
@akhilo Although I understand the explanation alright. But I'm really not sure how can it be non-atomic when the channel is returning a func
and variable are inside the func
body.
Can you please show me how did you test it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, thanks for sharing the idea.