Separate goroutines exercise into different files
Also went ahead and added a way to interactively select which function to execute so I can easily execute each file individually, I still have to learn channels and passing data through these channels but I don't want old code possibly bothering me
This commit is contained in:
parent
a4667e2039
commit
a89ca3987b
|
@ -0,0 +1,30 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func bgChecker() {
|
||||||
|
for {
|
||||||
|
if check == true {
|
||||||
|
fmt.Println("Check has been set to true, quitting")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fun1() {
|
||||||
|
go bgChecker()
|
||||||
|
for {
|
||||||
|
fmt.Printf("Would you like to set the check to true? [y/n] ")
|
||||||
|
fmt.Scanln(&choice)
|
||||||
|
if choice == "y" {
|
||||||
|
check = true
|
||||||
|
} else {
|
||||||
|
fmt.Println("Too bad")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,39 +2,26 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var check bool = false
|
var check bool = false
|
||||||
var choice string
|
var choice string
|
||||||
|
|
||||||
// func printText(s string) {
|
|
||||||
// for i := 0; i < 10; i++ {
|
|
||||||
// time.Sleep(time.Millisecond * 50)
|
|
||||||
// fmt.Println(s)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func bgChecker() {
|
|
||||||
for {
|
|
||||||
if check == true {
|
|
||||||
fmt.Println("WOOOOOOOOOOOO")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go bgChecker()
|
var numChoice int
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Printf("Would you like to set the check to true? [y/n] ")
|
fmt.Printf("[1] Basic concurrency\n")
|
||||||
fmt.Scanln(&choice)
|
|
||||||
if choice == "y" {
|
fmt.Printf("\rChoose your function: ")
|
||||||
check = true
|
fmt.Scanln(&numChoice)
|
||||||
} else {
|
|
||||||
fmt.Println("Too bad")
|
switch numChoice {
|
||||||
|
case 1:
|
||||||
|
fun1()
|
||||||
|
default:
|
||||||
|
fmt.Printf("Choose an actual function, please\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue