Codebase list golang-github-vbauerster-mpb / 18f2e3b
panic explicitly if Add is called after Progress is done Vladimir Bauer 6 years ago
1 changed file(s) with 5 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
33 "bytes"
44 "container/heap"
55 "context"
6 "fmt"
67 "io"
78 "io/ioutil"
89 "log"
9697 return p
9798 }
9899
99 // AddBar creates a new progress bar and adds to the container.
100 // AddBar creates a new progress bar and adds it to the rendering queue.
100101 func (p *Progress) AddBar(total int64, options ...BarOption) *Bar {
101102 return p.Add(total, NewBarFiller(DefaultBarStyle, false), options...)
102103 }
103104
104 // AddSpinner creates a new spinner bar and adds to the container.
105 // AddSpinner creates a new spinner bar and adds it to the rendering queue.
105106 func (p *Progress) AddSpinner(total int64, alignment SpinnerAlignment, options ...BarOption) *Bar {
106107 return p.Add(total, NewSpinnerFiller(DefaultSpinnerStyle, alignment), options...)
107108 }
108109
109110 // Add creates a bar which renders itself by provided filler.
110111 // Set total to 0, if you plan to update it later.
112 // Panics if *Progress instance is done, i.e. called after *Progress.Wait().
111113 func (p *Progress) Add(total int64, filler Filler, options ...BarOption) *Bar {
112114 if filler == nil {
113115 filler = NewBarFiller(DefaultBarStyle, false)
133135 return bar
134136 case <-p.done:
135137 p.bwg.Done()
136 return nil
138 panic(fmt.Sprintf("%T instance can't be reused after it's done!", p))
137139 }
138140 }
139141