Quick actions

cmd+k|ctrl+k

Navigation

Languages

Channels and select / Using range to read from a channel / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:15:08Z

Updated

2019-03-26T10:15:08Z

package main

import (
	"fmt"
)

func foo(ch chan int) {
	ch <- 1
	ch <- 2
	close(ch)
}

func main() {
	ch := make(chan int)
	go foo(ch)
	for n := range ch {
		fmt.Println(n)
	}
	fmt.Println("channel is now closed")
}
INFO