Quick actions

cmd+k|ctrl+k

Navigation

Languages

Essential Go / Channels and select

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:10:20Z

Updated

2019-03-26T10:10:20Z

package main

import (
	"fmt"
	"math/rand"
)

func genInts(chInts chan int) {
	chInts <- rand.Intn(1000)
}

func main() {
	chInts := make(chan int)
	for i := 0; i < 2; i++ {
		go genInts(chInts)
	}
	n := <-chInts
	fmt.Printf("n: %d\n", n)

	select {
	case n := <-chInts:
		fmt.Printf("n: %d\n", n)
	}
}
INFO