some godoc update
Vladimir Bauer
2 years ago
| 80 | 80 | return bar |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | // ProxyReader wraps io.Reader with metrics required for progress tracking. | |
| 84 | // If `r` is 'unknown total/size' reader it's mandatory to call | |
| 85 | // (*Bar).SetTotal(-1, true) method after (io.Reader).Read returns io.EOF. | |
| 86 | // If bar is already completed or aborted, returns nil. | |
| 83 | // ProxyReader wraps io.Reader with metrics required for progress | |
| 84 | // tracking. If `r` is 'unknown total/size' reader it's mandatory | |
| 85 | // to call `(*Bar).SetTotal(-1, true)` after the wrapper returns | |
| 86 | // `io.EOF`. If bar is already completed or aborted, returns nil. | |
| 87 | 87 | // Panics if `r` is nil. |
| 88 | 88 | func (b *Bar) ProxyReader(r io.Reader) io.ReadCloser { |
| 89 | 89 | if r == nil { |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | // EnableTriggerComplete enables triggering complete event. It's | |
| 179 | // effective only for bars which were constructed with `total <= 0` and | |
| 180 | // after total has been set with (*Bar).SetTotal(int64, false). If bar | |
| 181 | // has been incremented to the total, complete event is triggered right | |
| 182 | // away. | |
| 178 | // EnableTriggerComplete enables triggering complete event. It's effective | |
| 179 | // only for bars which were constructed with `total <= 0` and after total | |
| 180 | // has been set with `(*Bar).SetTotal(int64, false)`. If `curren >= total` | |
| 181 | // at the moment of call, complete event is triggered right away. | |
| 183 | 182 | func (b *Bar) EnableTriggerComplete() { |
| 184 | 183 | select { |
| 185 | 184 | case b.operateState <- func(s *bState) { |
| 198 | 197 | } |
| 199 | 198 | } |
| 200 | 199 | |
| 201 | // SetTotal sets total to an arbitrary value. It's effective only for | |
| 202 | // bar which was constructed with `total <= 0`. Setting total to negative | |
| 203 | // value is equivalent to (*Bar).SetTotal((*Bar).Current(), bool) but faster. | |
| 204 | // If triggerCompletion is true, total value is set to current and | |
| 205 | // complete event is triggered right away. | |
| 200 | // SetTotal sets total to an arbitrary value. It's effective only for bar | |
| 201 | // which was constructed with `total <= 0`. Setting total to negative value | |
| 202 | // is equivalent to `(*Bar).SetTotal((*Bar).Current(), bool)` but faster. If | |
| 203 | // triggerCompletion is true, total value is set to current and complete | |
| 204 | // event is triggered right away. | |
| 206 | 205 | func (b *Bar) SetTotal(total int64, triggerCompletion bool) { |
| 207 | 206 | select { |
| 208 | 207 | case b.operateState <- func(s *bState) { |
| 342 | 341 | // Abort interrupts bar's running goroutine. Abort won't be engaged |
| 343 | 342 | // if bar is already in complete state. If drop is true bar will be |
| 344 | 343 | // removed as well. To make sure that bar has been removed call |
| 345 | // (*Bar).Wait method. | |
| 344 | // `(*Bar).Wait()` method. | |
| 346 | 345 | func (b *Bar) Abort(drop bool) { |
| 347 | 346 | select { |
| 348 | 347 | case b.operateState <- func(s *bState) { |