-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathchannelSelect.go
67 lines (54 loc) · 1.01 KB
/
channelSelect.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
66
67
package main
import (
"fmt"
"strings"
)
var (
inputString, outputString string
length, lettersDone int
inputBytes []byte
applicationDone bool
)
func sendLetters(gq chan string) {
for i := 0; i < length; i++ {
gq <- string(inputBytes[i])
}
}
func capitalize(gq chan string, sq chan string) {
for {
if lettersDone >= length {
applicationDone = true
break
}
select {
case let := <-sq:
outputString += let
lettersDone++
case letter := <-gq:
letter = strings.ToUpper(letter)
sq <- letter
// outputString += letter
}
}
}
func main() {
applicationDone = false
gQueue := make(chan string)
sQueue := make(chan string)
fmt.Println("Lets start..")
lettersDone = 0
inputString = "we are who we are"
inputBytes = []byte(inputString)
length = len(inputBytes)
go sendLetters(gQueue)
capitalize(gQueue, sQueue)
close(gQueue)
close(sQueue)
for {
if applicationDone == true {
fmt.Println("Done")
fmt.Println(outputString)
break
}
}
}