pause: minor cleanups

This commit is contained in:
boyska 2018-12-25 01:27:27 +01:00
parent 64dc363de7
commit 518b8a5588
2 changed files with 11 additions and 7 deletions

View file

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

14
hub.go
View file

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