func CheckAndIncrement(counter Counter, incrVal, maxVal int64) error {
	val, err := counter.Total()
	if err != nil {
		return err
	}
	if val+incrVal > maxVal {
		return ErrLimitExceeded
	}
	return counter.IncrBy(incrVal)
}
// CheckAndIncrement is a simple strategy to check a counter value for the limit and
// increment it if the counter value is still under the limit.
// NOTE: This strategy is not precise due to race condition but this is sufficient in most cases.
CheckAndIncrement is a simple strategy to check a counter value for the limit and
increment it if the counter value is still under the limit.
NOTE: This strategy is not precise due to race condition but this is sufficient in most cases.
// CheckAndIncrement is a simple strategy to check a counter value for the limit and // increment it if the counter value is still under the limit . // NOTE : This strategy is not precise due to race condition but this is sufficient in most cases .
func CheckAndIncrement(counter Counter, incrVal, maxVal int64) error {
	val, err := counter.Total()
	if err != nil {
		return err
	}
	if val+incrVal > maxVal {
		return ErrLimitExceeded
	}
	return counter.IncrBy(incrVal)
}
func CheckAndIncrement ( counter Counter , incrVal , maxVal int64 ) error { val , err := counter . Total ( ) if err != nil { return err } if val + incrVal > maxVal { return ErrLimitExceeded } return counter . IncrBy ( incrVal ) }
CheckAndIncrement is a simple strategy to check a counter value for the limit and
increment it if the counter value is still under the limit.
CheckAndIncrement is a simple strategy to check a counter value for the limit and increment it if the counter value is still under the limit .