Skip to content

Instantly share code, notes, and snippets.

@slav
Created December 18, 2016 05:00
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save slav/ca2ee333c29b8f76b557c9b10b371b52 to your computer and use it in GitHub Desktop.
Save slav/ca2ee333c29b8f76b557c9b10b371b52 to your computer and use it in GitHub Desktop.
Golang sending sending multiple values through channel
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)
}
@slav
Copy link
Author

slav commented Dec 13, 2019

Cool, thanks for sharing the idea.

@meetme2meat
Copy link

meetme2meat commented Jan 13, 2020

@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