dry render branches
Vladimir Bauer
3 years ago
| 203 | 203 | |
| 204 | 204 | p.refreshCh = s.newTicker(p.done) |
| 205 | 205 | |
| 206 | render := func(debugOut io.Writer) { | |
| 207 | err := s.render(cw) | |
| 208 | for err != nil { | |
| 209 | if debugOut != nil { | |
| 210 | _, err = fmt.Fprintln(debugOut, err) | |
| 211 | } else { | |
| 212 | panic(err) | |
| 213 | } | |
| 214 | debugOut = nil | |
| 215 | } | |
| 216 | } | |
| 217 | ||
| 206 | 218 | for { |
| 207 | 219 | select { |
| 208 | 220 | case op := <-p.operateState: |
| 209 | 221 | op(s) |
| 210 | 222 | case <-p.refreshCh: |
| 211 | if err := s.render(cw); err != nil { | |
| 212 | if s.debugOut != nil { | |
| 213 | _, e := fmt.Fprintln(s.debugOut, err) | |
| 214 | if e != nil { | |
| 215 | panic(err) | |
| 216 | } | |
| 217 | } else { | |
| 218 | panic(err) | |
| 219 | } | |
| 220 | } | |
| 223 | render(s.debugOut) | |
| 221 | 224 | case <-s.shutdownNotifier: |
| 222 | 225 | for s.heapUpdated { |
| 223 | if err := s.render(cw); err != nil { | |
| 224 | if s.debugOut != nil { | |
| 225 | _, e := fmt.Fprintln(s.debugOut, err) | |
| 226 | if e != nil { | |
| 227 | panic(err) | |
| 228 | } | |
| 229 | } else { | |
| 230 | panic(err) | |
| 231 | } | |
| 232 | } | |
| 226 | render(s.debugOut) | |
| 233 | 227 | } |
| 234 | 228 | return |
| 235 | 229 | } |