Pass *bState intead of bState
Vladimir Bauer
8 years ago
| 35 | 35 | ops chan func(*bState) |
| 36 | 36 | |
| 37 | 37 | // following are used after b.done is receiveable |
| 38 | cacheState bState | |
| 38 | cacheState *bState | |
| 39 | 39 | |
| 40 | 40 | once sync.Once |
| 41 | 41 | } |
| 79 | 79 | total = time.Now().Unix() |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | s := bState{ | |
| 82 | s := &bState{ | |
| 83 | 83 | id: ID, |
| 84 | 84 | total: total, |
| 85 | 85 | etaAlpha: etaAlpha, |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | for _, opt := range options { |
| 90 | opt(&s) | |
| 90 | opt(s) | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | s.bufP = bytes.NewBuffer(make([]byte, 0, s.width/2)) |
| 265 | 265 | close(b.quit) |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | func (b *Bar) server(s bState, wg *sync.WaitGroup, cancel <-chan struct{}) { | |
| 268 | func (b *Bar) server(s *bState, wg *sync.WaitGroup, cancel <-chan struct{}) { | |
| 269 | 269 | defer func() { |
| 270 | 270 | b.cacheState = s |
| 271 | 271 | close(b.done) |
| 275 | 275 | for { |
| 276 | 276 | select { |
| 277 | 277 | case op := <-b.ops: |
| 278 | op(&s) | |
| 278 | op(s) | |
| 279 | 279 | case <-cancel: |
| 280 | 280 | s.aborted = true |
| 281 | 281 | cancel = nil |