Skip to content

Instantly share code, notes, and snippets.

@ekusiadadus
Created November 6, 2022 19:39
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 ekusiadadus/dc90ca87f430c9238807084c5ae15b6a to your computer and use it in GitHub Desktop.
Save ekusiadadus/dc90ca87f430c9238807084c5ae15b6a to your computer and use it in GitHub Desktop.
chanel
package main
func goroutine1(s []int, c chan int) {
sum := 0
for _, v := range s {
sum += v
}
c <- sum
}
func main() {
s := []int{1, 2, 3, 4, 5}
c := make(chan int)
go goroutine1(s, c)
x := <-c
println(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment