-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (44 loc) · 833 Bytes
/
main.go
File metadata and controls
58 lines (44 loc) · 833 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
package main
import (
"fmt"
"time"
)
func printAfterDelay(delay time.Duration) {
time.Sleep(delay)
fmt.Println("Delayed Message!")
}
func add(a int, b int, out chan int) {
c := a + b
out <- c
}
func printer(in chan int) {
for {
result := <-in
time.Sleep(2000 * time.Millisecond)
fmt.Println(result)
}
}
func example1() {
fmt.Println("example 1: start..")
go printAfterDelay(2000 * time.Millisecond)
fmt.Println("continue..")
time.Sleep(3000 * time.Millisecond)
fmt.Println("example 1: end..")
}
func example2() {
fmt.Println("example 2: start..")
// setup chanel
c := make(chan int)
//init printer
go printer(c)
//add numbers
go add(5, 4, c)
time.Sleep(3000 * time.Millisecond)
fmt.Println("example 2: end..")
}
func main() {
// First example
example1()
// Second example
//example2()
}