// ctxProgress creates a rate-limited progress callback for the provided
// context. It returns nil if a callback has not been set.
ctxProgress creates a rate-limited progress callback for the provided
context. It returns nil if a callback has not been set.
// ctxProgress creates a rate - limited progress callback for the provided // context . It returns nil if a callback has not been set .
func ctxProgress(ctx context.Context) func(force bool, n, total int) {
	if v := ctx.Value(progressKey{}); v != nil {
		fn := v.(func(n, total int))
		dt := ctx.Value(progressDeltaKey{}).(float64)
		var pct, lastPct float64
		return func(force bool, n, total int) {
			if dt < 0 || dt > 1 {
				fn(n, total)
				return
			}
			if n == 0 && total == 0 {
				pct = 1
			} else if n == 0 || total == 0 {
				pct = 0
			} else {
				pct = float64(n) / float64(total)
			}
			if force || math.Abs(pct-lastPct) >= dt {
				lastPct = pct
				fn(n, total)
			}
		}
	}
	return nil
}
func ctxProgress ( ctx context . Context ) func ( force bool , n , total int ) { if v := ctx . Value ( progressKey { } ) ; v != nil { fn := v . ( func ( n , total int ) ) dt := ctx . Value ( progressDeltaKey { } ) . ( float64 ) var pct , lastPct float64 return func ( force bool , n , total int ) { if dt < 0 || dt > 1 { fn ( n , total ) return } if n == 0 && total == 0 { pct = 1 } else if n == 0 || total == 0 { pct = 0 } else { pct = float64 ( n ) / float64 ( total ) } if force || math . Abs ( pct - lastPct ) >= dt { lastPct = pct fn ( n , total ) } } } return nil }
ctxProgress creates a rate-limited progress callback for the provided
context.
ctxProgress creates a rate - limited progress callback for the provided context .