Codebase list golang-github-vbauerster-mpb / 795c4be
update godoc Vladimir Bauer 2 years ago
1 changed file(s) with 13 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1717 defaultRefreshRate = 150 * time.Millisecond
1818 )
1919
20 // DoneError represents an error when `*mpb.Progress` is done but its functionality is requested.
21 var DoneError = fmt.Errorf("%T instance can't be reused after it's done", (*Progress)(nil))
20 // DoneError represents use after `(*Progress).Wait()` error.
21 var DoneError = fmt.Errorf("%T instance can't be reused after %[1]T.Wait()", (*Progress)(nil))
2222
2323 // Progress represents a container that renders one or more progress bars.
2424 type Progress struct {
5454 }
5555
5656 // New creates new Progress container instance. It's not possible to
57 // reuse instance after (*Progress).Wait method has been called.
57 // reuse instance after `(*Progress).Wait` method has been called.
5858 func New(options ...ContainerOption) *Progress {
5959 return NewWithContext(context.Background(), options...)
6060 }
6161
6262 // NewWithContext creates new Progress container instance with provided
63 // context. It's not possible to reuse instance after (*Progress).Wait
63 // context. It's not possible to reuse instance after `(*Progress).Wait`
6464 // method has been called.
6565 func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress {
6666 if ctx == nil {
132132
133133 // MustAdd creates a bar which renders itself by provided BarFiller.
134134 // If `total <= 0` triggering complete event by increment methods is
135 // disabled. Panics if *Progress instance is done, i.e. called after
136 // (*Progress).Wait().
135 // disabled. Panics if called after `(*Progress).Wait()`.
137136 func (p *Progress) MustAdd(total int64, filler BarFiller, options ...BarOption) *Bar {
138137 bar, err := p.Add(total, filler, options...)
139138 if err != nil {
144143
145144 // Add creates a bar which renders itself by provided BarFiller.
146145 // If `total <= 0` triggering complete event by increment methods
147 // is disabled. If *Progress instance is done, i.e. called after
148 // (*Progress).Wait(), return error == DoneError.
146 // is disabled. If called after `(*Progress).Wait()` then
147 // `(nil, DoneError)` is returned.
149148 func (p *Progress) Add(total int64, filler BarFiller, options ...BarOption) (*Bar, error) {
150149 if filler == nil {
151150 filler = NopStyle().Build()
202201
203202 // UpdateBarPriority either immediately or lazy.
204203 // With lazy flag order is updated after the next refresh cycle.
205 // If you don't care about laziness just use *Bar.SetPriority(int).
204 // If you don't care about laziness just use `(*Bar).SetPriority(int)`.
206205 func (p *Progress) UpdateBarPriority(b *Bar, priority int, lazy bool) {
207206 if b == nil {
208207 return
214213 }
215214
216215 // Write is implementation of io.Writer.
217 // Writing to `*mpb.Progress` will print lines above a running bar.
216 // Writing to `*Progress` will print lines above a running bar.
218217 // Writes aren't flushed immediately, but at next refresh cycle.
219 // If Write is called after `*mpb.Progress` is done, `mpb.DoneError`
218 // If called after `(*Progress).Wait()` then `(0, DoneError)`
220219 // is returned.
221220 func (p *Progress) Write(b []byte) (int, error) {
222221 type result struct {
237236 }
238237
239238 // Wait waits for all bars to complete and finally shutdowns container. After
240 // this method has been called, there is no way to reuse (*Progress) instance.
239 // this method has been called, there is no way to reuse `*Progress` instance.
241240 func (p *Progress) Wait() {
242241 // wait for user wg, if any
243242 if p.uwg != nil {
248247 p.Shutdown()
249248 }
250249
251 // Shutdown cancels any running bar immediately and then shutdowns (*Progress)
250 // Shutdown cancels any running bar immediately and then shutdowns `*Progress`
252251 // instance. Normally this method shouldn't be called unless you know what you
253 // are doing. Proper way to shutdown is to call (*Progress).Wait() instead.
252 // are doing. Proper way to shutdown is to call `(*Progress).Wait()` instead.
254253 func (p *Progress) Shutdown() {
255254 p.cancel()
256255 p.pwg.Wait()