Changes

Jump to: navigation, search

Team Go

365 bytes added, 00:03, 18 December 2017
no edit summary
</source>
produces the output :
<source>
== Channels ==
Channels are what Goroutines use to communicate with each other. Channels They help Goroutines synchronize their execution. Channels can have directions that restrict them to just sending or receiving. Channels can have several characteristicsparts to them: the type of element you can send through a channel, its capacity (or buffer size) and the direction of communication which is specified by using a <- operator. <source lang ="go">package main import "fmt" func sum(s []int, c chan int) { sum := 0 for _, v := range s { sum += v } c <- sum // send sum to c} func main() { s := []int{7, 2, 8, -9, 4, 0}  c := make(chan int) go sum(s[:len(s)/2], c) go sum(s[len(s)/2:], c) x, y := <-c, <-c // receive from c  fmt.Println(x, y, x+y)}</source>
32
edits

Navigation menu