From 518b8a558832d34b8e229bbf694edff9040fcd6a Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 25 Dec 2018 01:27:27 +0100 Subject: [PATCH] pause: minor cleanups --- cmd/circologd/http_ctl.go | 4 +++- hub.go | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/circologd/http_ctl.go b/cmd/circologd/http_ctl.go index d47eec8..8915172 100644 --- a/cmd/circologd/http_ctl.go +++ b/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 { diff --git a/hub.go b/hub.go index 7d160c2..9305b0a 100644 --- a/hub.go +++ b/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 }