BarsCount method
Vladimir Bauer
9 years ago
| 38 | 38 | op chan *operation |
| 39 | 39 | rrChangeReqCh chan time.Duration |
| 40 | 40 | outChangeReqCh chan io.Writer |
| 41 | countReqCh chan chan int | |
| 41 | 42 | |
| 42 | 43 | wg *sync.WaitGroup |
| 43 | 44 | } |
| 55 | 56 | op: make(chan *operation), |
| 56 | 57 | rrChangeReqCh: make(chan time.Duration), |
| 57 | 58 | outChangeReqCh: make(chan io.Writer), |
| 59 | countReqCh: make(chan chan int), | |
| 58 | 60 | wg: new(sync.WaitGroup), |
| 59 | 61 | } |
| 60 | 62 | go p.server(cwriter.New(os.Stdout), time.NewTicker(rr*time.Millisecond)) |
| 104 | 106 | return <-result |
| 105 | 107 | } |
| 106 | 108 | |
| 109 | func (p *Progress) BarsCount() int { | |
| 110 | respCh := make(chan int) | |
| 111 | p.countReqCh <- respCh | |
| 112 | return <-respCh | |
| 113 | } | |
| 114 | ||
| 107 | 115 | // WaitAndStop stops listening |
| 108 | 116 | func (p *Progress) WaitAndStop() { |
| 109 | 117 | if !p.stopped { |
| 146 | 154 | } |
| 147 | 155 | op.result <- ok |
| 148 | 156 | } |
| 157 | case respCh := <-p.countReqCh: | |
| 158 | respCh <- len(bars) | |
| 149 | 159 | case <-t.C: |
| 150 | 160 | switch p.sort { |
| 151 | 161 | case SortTop: |