proof of width sync conept
Vladimir Bauer
9 years ago
| 246 | 246 | if isClosed(b.done) { |
| 247 | 247 | return b.state |
| 248 | 248 | } |
| 249 | ch := make(chan state, 1) | |
| 249 | // ch := make(chan state, 1) | |
| 250 | ch := make(chan state) | |
| 250 | 251 | b.stateReqCh <- ch |
| 251 | 252 | return <-ch |
| 252 | 253 | } |
| 357 | 358 | } |
| 358 | 359 | |
| 359 | 360 | func draw(s *state, termWidth int, ws *widthSync) []byte { |
| 361 | if len(s.prependFuncs) != len(ws.listen) { | |
| 362 | return []byte{} | |
| 363 | } | |
| 360 | 364 | if termWidth <= 0 { |
| 361 | 365 | termWidth = s.width |
| 362 | 366 | } |
| 296 | 296 | for i := 0; i < numBars; i++ { |
| 297 | 297 | resultCh <- result |
| 298 | 298 | } |
| 299 | // close(resultCh) | |
| 299 | close(resultCh) | |
| 300 | 300 | }(listenCh, prepWidthSync.result[i]) |
| 301 | 301 | } |
| 302 | 302 | |
| 306 | 306 | wg.Add(numBars) |
| 307 | 307 | for i := 0; i < numBars; i++ { |
| 308 | 308 | go func() { |
| 309 | defer recoverIfPanic() | |
| 309 | // defer recoverIfPanic() | |
| 310 | defer func() { | |
| 311 | wg.Done() | |
| 312 | }() | |
| 310 | 313 | drawer(ibars, ibbCh, prepWidthSync) |
| 311 | 314 | }() |
| 312 | 315 | } |
| 314 | 317 | wg.Wait() |
| 315 | 318 | close(ibbCh) |
| 316 | 319 | close(stopWidthListen) |
| 317 | for _, ch := range prepWidthSync.result { | |
| 318 | close(ch) | |
| 319 | } | |
| 320 | 320 | for _, ch := range prepWidthSync.listen { |
| 321 | 321 | close(ch) |
| 322 | 322 | } |