move newTicker close to call
Vladimir Bauer
6 years ago
| 222 | 222 | return |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | } | |
| 226 | ||
| 227 | func (s *pState) newTicker(done <-chan struct{}) chan time.Time { | |
| 228 | ch := make(chan time.Time) | |
| 229 | if s.shutdownNotifier == nil { | |
| 230 | s.shutdownNotifier = make(chan struct{}) | |
| 231 | } | |
| 232 | go func() { | |
| 233 | if s.renderDelay != nil { | |
| 234 | <-s.renderDelay | |
| 235 | } | |
| 236 | if s.refreshSrc == nil { | |
| 237 | ticker := time.NewTicker(s.rr) | |
| 238 | defer ticker.Stop() | |
| 239 | s.refreshSrc = ticker.C | |
| 240 | } | |
| 241 | for { | |
| 242 | select { | |
| 243 | case tick := <-s.refreshSrc: | |
| 244 | ch <- tick | |
| 245 | case <-done: | |
| 246 | close(s.shutdownNotifier) | |
| 247 | return | |
| 248 | } | |
| 249 | } | |
| 250 | }() | |
| 251 | return ch | |
| 225 | 252 | } |
| 226 | 253 | |
| 227 | 254 | func (s *pState) render(cw *cwriter.Writer) error { |
| 301 | 328 | return cw.Flush(lineCount) |
| 302 | 329 | } |
| 303 | 330 | |
| 304 | func (s *pState) newTicker(done <-chan struct{}) chan time.Time { | |
| 305 | ch := make(chan time.Time) | |
| 306 | if s.shutdownNotifier == nil { | |
| 307 | s.shutdownNotifier = make(chan struct{}) | |
| 308 | } | |
| 309 | go func() { | |
| 310 | if s.renderDelay != nil { | |
| 311 | <-s.renderDelay | |
| 312 | } | |
| 313 | if s.refreshSrc == nil { | |
| 314 | ticker := time.NewTicker(s.rr) | |
| 315 | defer ticker.Stop() | |
| 316 | s.refreshSrc = ticker.C | |
| 317 | } | |
| 318 | for { | |
| 319 | select { | |
| 320 | case tick := <-s.refreshSrc: | |
| 321 | ch <- tick | |
| 322 | case <-done: | |
| 323 | close(s.shutdownNotifier) | |
| 324 | return | |
| 325 | } | |
| 326 | } | |
| 327 | }() | |
| 328 | return ch | |
| 329 | } | |
| 330 | ||
| 331 | 331 | func (s *pState) updateSyncMatrix() { |
| 332 | 332 | s.pMatrix = make(map[int][]chan int) |
| 333 | 333 | s.aMatrix = make(map[int][]chan int) |