Golang builtin.close() function example

package builtin

The close built-in function closes a channel, which must be either bidirectional or send-only. It should be executed only by the sender, never the receiver, and has the effect of shutting down the channel after the last sent value is received.

Golang builtin.close() function usage example

 jobs := make(chan Job)

 go func() {
 for _, job := range jobList {
 jobs <- job // Blocks waiting for a receive
 }
 close(jobs) // close the channel
 }()

Reference :

http://golang.org/pkg/builtin/#close

Advertisement