Browse Source

pause: minor cleanups

boyska 5 years ago
parent
commit
518b8a5588
2 changed files with 11 additions and 7 deletions
  1. 3 1
      cmd/circologd/http_ctl.go
  2. 8 6
      hub.go

+ 3 - 1
cmd/circologd/http_ctl.go

@@ -34,7 +34,9 @@ func togglePause(hub circolog.Hub, verbose, debug bool) http.HandlerFunc {
 		if waitTimePar != "" {
 			waitTime, err = time.ParseDuration(waitTimePar)
 			if err != nil {
-				fmt.Println("waitTime not understood:", waitTimePar)
+				w.WriteHeader(400)
+				fmt.Fprintln(w, "waitTime not understood:", waitTimePar)
+				return
 			}
 		}
 		if debug {

+ 8 - 6
hub.go

@@ -131,6 +131,10 @@ func (h *Hub) Run() {
 			}
 			if cmd.Command == CommandPauseToggle {
 				togglePause(cmd.Parameters["waitTime"].(time.Duration), &active)
+				if active {
+					fmt.Print("un")
+				}
+				fmt.Println("paused")
 				cmd.Response <- CommandResponse{Value: active}
 			}
 		}
@@ -138,14 +142,12 @@ func (h *Hub) Run() {
 }
 
 func togglePause(waitTime time.Duration, status *bool) {
-	var noTime time.Duration
-	if waitTime != noTime {
-		delayedToggle := func() {
+	if waitTime != 0 {
+		go func() {
 			time.Sleep(waitTime)
 			fmt.Fprintln(os.Stderr, "toggling again")
-			togglePause(noTime, status)
-		}
-		go delayedToggle()
+			togglePause(0, status)
+		}()
 	}
 	*status = !*status
 }