-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathchan.go
More file actions
74 lines (60 loc) · 834 Bytes
/
Copy pathchan.go
File metadata and controls
74 lines (60 loc) · 834 Bytes
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Example make(chan)
*
* @package main
* @author @jeffotoni
* @size 01/08/2017
*
*/
package main
import (
"fmt"
"log"
"time"
)
const (
Wirte = iota
Read
Execute
)
func EvenOne(even chan int) {
log.Println(Read)
return
i := 2
for i < 9 {
even <- i
i = i + 2
}
close(even)
}
func OldOne(odd chan int) {
i := 1
for i < 9 {
odd <- i
i = i + 2
time.Sleep(time.Second * 2)
}
close(odd)
}
func main() {
println(Read)
return
even := make(chan int)
odd := make(chan int)
go EvenOne(even)
go OldOne(odd)
fmt.Println("for here:")
for {
even, ok1 := <-even
odd, ok2 := <-odd
if ok1 == false && ok2 == false {
break
}
fmt.Println("Received even: ", even, ok1, " one: ", odd, ok2)
}
ch := make(chan int, 2)
ch <- 5
ch <- 6
fmt.Println(<-ch)
fmt.Println(<-ch)
}