-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
109 lines (89 loc) · 2.22 KB
/
app.go
File metadata and controls
109 lines (89 loc) · 2.22 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"fmt"
"time"
"os/exec"
)
var(
currentExercise = 1
allExercises = 5
)
func main() {
exercise := make(chan bool)
shortRest := make(chan bool)
longRest := make(chan bool)
done := make(chan bool)
go circuit(exercise)
go circuitService(exercise, shortRest, longRest, done)
<-done
}
func circuit(exerciseChan chan bool) {
beginExercise()
time.Sleep(time.Minute*2)
endExercise()
exerciseChan <- true
}
func shortRest(restChan chan bool) {
beginShortRest()
time.Sleep(time.Minute)
endShortRest()
restChan <- true
}
func longRest(longRestChan chan bool) {
beginLongRest()
time.Sleep(time.Minute*2)
longRestChan <- true
}
func beginExercise() {
exec.Command("say", "Exercise begins").Output()
}
func endExercise() {
exec.Command("say", "Exercise ends").Output()
}
func beginShortRest() {
exec.Command("say", "Short rest begins").Output()
}
func endShortRest() {
exec.Command("say", "Short rest ends").Output()
}
func beginLongRest() {
exec.Command("say", "Long rest begins").Output()
}
func endLongRest() {
exec.Command("say", "Long rest ends").Output()
}
func circuitService(exerciseChan, shortRestChan, longRestChan, doneChan chan bool) {
for {
select {
case endExercise := <-exerciseChan:
_ = endExercise
if currentExercise >= allExercises {
go longRest(longRestChan)
currentExercise = 1
} else {
currentExercise += 1
go shortRest(shortRestChan)
}
case endShortRest := <-shortRestChan:
_ = endShortRest
go circuit(exerciseChan)
case endLongRest := <-longRestChan:
_ = endLongRest
input := askUser()
for input != "Y" && input != "N" {
input = askUser()
}
if input == "Y" {
go circuit(exerciseChan)
} else {
doneChan <- true
}
}
}
}
func askUser() string {
fmt.Println("Would you like to continue with another circuit? (Y/N)")
var response string
fmt.Scanln(&response)
return response
}