diff --git a/golangr/goroutines/1.go b/golangr/goroutines/1.go new file mode 100644 index 0000000..f397197 --- /dev/null +++ b/golangr/goroutines/1.go @@ -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") + } + } +} diff --git a/golangr/goroutines/main.go b/golangr/goroutines/main.go index dae4a53..6e30f5a 100644 --- a/golangr/goroutines/main.go +++ b/golangr/goroutines/main.go @@ -2,39 +2,26 @@ package main import ( "fmt" - "os" - "time" ) var check bool = false 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() { - go bgChecker() + var numChoice int + 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") + fmt.Printf("[1] Basic concurrency\n") + + fmt.Printf("\rChoose your function: ") + fmt.Scanln(&numChoice) + + switch numChoice { + case 1: + fun1() + default: + fmt.Printf("Choose an actual function, please\n") } } + }