-
Notifications
You must be signed in to change notification settings - Fork 4
/
test4_channel.go
65 lines (49 loc) · 1.06 KB
/
test4_channel.go
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
/*
*
* Program to do a load test, and validate the response team of our api
*
* @package main
* @author @jeffotoni
* @size 29/07/2017
*
*/
package main
import (
"fmt"
Shoot "github.com/jeffotoni/printserver/pkg"
"time"
)
func main() {
// For our example we'll select across two channels.
c1 := make(chan string)
c2 := make(chan string)
endPoint1 := "http://localhost:9001/ping"
endPoint2 := "http://localhost:9001/ping2"
go func() {
for i := 0; i < 10; i++ {
time.Sleep(time.Millisecond * 100)
Shoot.ShootUrl(endPoint1)
}
c2 <- "two"
}()
// Each channel will receive a value after some amount
// of time, to simulate e.g. blocking RPC operations
// executing in concurrent goroutines.
go func() {
for i := 0; i < 10; i++ {
time.Sleep(time.Millisecond * 300)
Shoot.ShootUrl(endPoint2)
}
c1 <- "one"
}()
msg := <-c2
fmt.Println(msg)
// for i := 0; i < 2; i++ {
// select {
// case msg1 := <-c1:
// fmt.Println("received", msg1)
// case msg2 := <-c2:
// fmt.Println("received", msg2)
// }
// }
}