golang-exercises/golangr/goroutines/main.go

41 lines
555 B
Go
Raw Normal View History

2024-02-26 11:59:46 +01:00
package main
import (
"fmt"
"os"
2024-02-26 11:59:46 +01:00
"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)
2024-02-26 11:59:46 +01:00
}
}
func main() {
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")
}
}
2024-02-26 11:59:46 +01:00
}