-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (33 loc) · 807 Bytes
/
main.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
package main
import (
"fmt"
"time"
"math/rand"
"strconv"
)
var commandQueue = make(chan string, 1) //Single Channel for handling this is all we need.
var QueueSleepInterval = struct{ min, max int }{1, 3}
func test(){
for {
wsi := QueueSleepInterval
s := rand.Intn(wsi.max-wsi.min) + wsi.min
time.Sleep(time.Duration(s) * time.Second)
data := <-commandQueue
fmt.Println("[",time.Now().Format(time.RFC850),"]", data)
}
}
func main() {
var i = 0
go test()
fmt.Println("Start Test.")
commandQueue <- "Command A"
time.Sleep(time.Duration(5) * time.Second)
commandQueue <- "Command B"
time.Sleep(time.Duration(5) * time.Second)
commandQueue <- "Command C"
for{
time.Sleep(time.Duration(10) * time.Second)
commandQueue <- "New Command Added [" + strconv.Itoa(i) +"]"
i++
}
}