O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Channels and data communication

Go is a statically typed language, and this means that a given channel can only send or receive data of a single data type. In Go's terminology, this is known as a channel's element type. A Go channel will accept any valid Go data type including functions. Here is an example of a simple program that accepts and calls on functions:

// elems.go package main import "fmt" func main() { // Let's create three simple functions that take an int argument fcn1 := func(i int) { fmt.Println("fcn1", i) } fcn2 := func(i int) { fmt.Println("fcn2", i*2) } fcn3 := func(i int) { fmt.Println("fcn3", i*3) } ch := make(chan func(int)) // Channel that sends & receives functions that take an int argument done := make(chan bool) // ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required