~kotrunga/a-tour-of-go

a-tour-of-go/concurrency/3.3_buffered-channels.go -rw-r--r-- 387 bytes View raw
b3f98925kotrunga remove .DS_Store file 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
	Notes 3.3

	Channels can be buffered- provide the length during channel creation with make().

	"Sends to a buffered channel block only when the buffer is full. Receives block
	when the buffer is empty."

	If you overfill the buffer, you'll get an error.
*/

package main

import "fmt"

func main() {
	ch := make(chan int, 2)
	ch <- 1
	ch <- 2
	fmt.Println(<-ch)
	fmt.Println(<-ch)
}