Skip to content

Commit

Permalink
IncrInt64 method
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Apr 27, 2019
1 parent ac88c5b commit ea8db49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
19 changes: 12 additions & 7 deletions bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,23 @@ func (b *Bar) SetCurrent(current int64, wdd ...time.Duration) {
b.arbitraryCurrent.Unlock()
}

// Increment is a shorthand for b.IncrBy(1).
func (b *Bar) Increment() {
b.IncrBy(1)
// Increment is a shorthand for b.IncrInt64(1).
func (b *Bar) Increment(wdd ...time.Duration) {
b.IncrInt64(1, wdd...)
}

// IncrBy increments progress bar by amount of n.
// wdd is optional work duration i.e. time.Since(start), which expected
// to be provided, if any ewma based decorator is used.
// IncrBy is a shorthand for b.IncrInt64(int64(n), wdd...).
func (b *Bar) IncrBy(n int, wdd ...time.Duration) {
b.IncrInt64(int64(n), wdd...)
}

// IncrInt64 increments progress bar by amount of n. wdd is an optional
// work duration i.e. time.Since(start), which expected to be passed,
// if any ewma based decorator is used.
func (b *Bar) IncrInt64(n int64, wdd ...time.Duration) {
select {
case b.operateState <- func(s *bState) {
s.current += int64(n)
s.current += n
if s.total > 0 && s.current >= s.total {
s.current = s.total
s.toComplete = true
Expand Down
2 changes: 1 addition & 1 deletion decor/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type OnCompleteMessenger interface {
// If decorator needs to receive increment amount, so this is the right
// interface to implement.
type AmountReceiver interface {
NextAmount(int, ...time.Duration)
NextAmount(int64, ...time.Duration)
}

// ShutdownListener interface.
Expand Down
2 changes: 1 addition & 1 deletion decor/eta.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (d *movingAverageETA) Decor(st *Statistics) string {
return d.FormatMsg(str)
}

func (d *movingAverageETA) NextAmount(n int, wdd ...time.Duration) {
func (d *movingAverageETA) NextAmount(n int64, wdd ...time.Duration) {
var workDuration time.Duration
for _, wd := range wdd {
workDuration = wd
Expand Down
2 changes: 1 addition & 1 deletion decor/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (d *movingAverageSpeed) Decor(st *Statistics) string {
return d.FormatMsg(d.msg)
}

func (d *movingAverageSpeed) NextAmount(n int, wdd ...time.Duration) {
func (d *movingAverageSpeed) NextAmount(n int64, wdd ...time.Duration) {
var workDuration time.Duration
for _, wd := range wdd {
workDuration = wd
Expand Down

0 comments on commit ea8db49

Please sign in to comment.