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 != "" {
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 {

14
hub.go
View file

@ -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
}