-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path17_channel.go
More file actions
41 lines (33 loc) · 1.04 KB
/
Copy path17_channel.go
File metadata and controls
41 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Čtvrtá část
// Rozhraní, metody, gorutiny a kanály v programovacím jazyku Go
// https://www.root.cz/clanky/rozhrani-metody-gorutiny-a-kanaly-v-programovacim-jazyku-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů ze čtvrté části:
// https://github.com/tisnik/go-root/blob/master/article_04/README.md
//
// Demonstrační příklad číslo 17:
// Kanál použitý pro komunikaci a synchronizaci mezi gorutinami.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_04/17_channel.html
package main
import "fmt"
func message(id int, channel chan int) {
fmt.Printf("gorutina %d\n", id)
channel <- 1
}
func main() {
channel := make(chan int)
fmt.Println("main begin")
go message(1, channel)
fmt.Println("waiting...")
code, status := <-channel
fmt.Printf("received code: %d and status: %t\n", code, status)
fmt.Println("main end")
}