Queer European MD passionate about IT
Browse Source

Moved user interactions to separate goroutine

Davide 1 year ago
parent
commit
340e193ab6
1 changed files with 9 additions and 4 deletions
  1. 9 4
      helper/helper.go

+ 9 - 4
helper/helper.go

@@ -145,7 +145,7 @@ func StringOscillator(s string, amplitude int) chan string {
 	return c
 }
 
-func ClickRepeteadly(s *SavedGroups) {
+func ClickRepeteadly(s *SavedGroups, c chan os.Signal) {
 	for index, g := range s.Groups {
 		fmt.Printf("- Press %v to select %v\n", index+1, g.Name)
 	}
@@ -188,6 +188,7 @@ func ClickRepeteadly(s *SavedGroups) {
 		}
 		if t >= 10 {
 			fmt.Println("You stayed away too long, exiting...")
+			c <- os.Interrupt
 			return
 		}
 	}
@@ -203,15 +204,19 @@ func cleanUp(c chan os.Signal) chan int {
 	return r
 }
 
+func interactWithUser(s *SavedGroups, yamlFile string, c chan os.Signal) {
+	addSavedGroup(s)
+	storeSavedGroups(s, yamlFile)
+	ClickRepeteadly(s, c)
+}
+
 func RunAutoClicker() {
 	c := make(chan os.Signal, 1)
 	quit := cleanUp(c)
 	signal.Notify(c, os.Interrupt)
 	yamlFile := "SavedGroups.yaml"
 	s := getSavedGroups(yamlFile)
-	addSavedGroup(s)
-	storeSavedGroups(s, yamlFile)
-	go ClickRepeteadly(s)
+	go interactWithUser(s, yamlFile, c)
 	if <-quit == 1 {
 		fmt.Println("Exiting...")
 	} else {