Skip to content

Commit

Permalink
refactor: use Math.min and Math.max instead of custom methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Nov 16, 2023
1 parent 204e19b commit 799a51c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
7 changes: 0 additions & 7 deletions src/math.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { HttpOptions } from './http-options';
import { suffixSlash, resolveUrl } from './url-utils';
import { UnleashEvents } from './events';
import { getAppliedJitter } from './helpers';
import { max, min } from './math';

export interface MetricsOptions {
appName: string;
Expand Down Expand Up @@ -198,7 +197,7 @@ export default class Metrics extends EventEmitter {
}

backoff(url: string, statusCode: number): void {
this.failures = min(10, this.failures + 1);
this.failures = Math.min(10, this.failures + 1);
// eslint-disable-next-line max-len
this.emit(UnleashEvents.Warn, `${url} returning ${statusCode}. Backing off to ${this.getInterval()}`);
this.startTimer();
Expand Down Expand Up @@ -253,7 +252,7 @@ export default class Metrics extends EventEmitter {
}

reduceBackoff(): void {
this.failures = max(0, this.failures - 1);
this.failures = Math.max(0, this.failures - 1);
this.startTimer();
}

Expand Down
5 changes: 2 additions & 3 deletions src/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { BootstrapProvider } from './bootstrap-provider';
import { StorageProvider } from './storage-provider';
import { UnleashEvents } from '../events';
import { Segment } from '../strategy/strategy';
import { max, min } from '../math';

const SUPPORTED_SPEC_VERSION = '4.3.0';

Expand Down Expand Up @@ -258,12 +257,12 @@ Message: ${err.message}`,
}

private backoff(): number {
this.failures = min(this.failures + 1, 10);
this.failures = Math.min(this.failures + 1, 10);
return this.nextFetch();
}

private countSuccess(): number {
this.failures = max(this.failures - 1, 0);
this.failures = Math.max(this.failures - 1, 0);
return this.nextFetch();
}

Expand Down

0 comments on commit 799a51c

Please sign in to comment.