Skip to content

Commit

Permalink
chore: Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Jul 14, 2021
1 parent 2745d66 commit 32ab5e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions spec/operators/retry-spec.ts
Expand Up @@ -86,7 +86,7 @@ describe('retry', () => {
});
});

it('should retry a number of times, then call error handler (with resetOnSuccess)', (done) => {
it('should retry a number of times, then call error handler (with resetOnFirstValue)', (done) => {
let errors = 0;
const retries = 2;
new Observable((observer: Observer<number>) => {
Expand All @@ -98,7 +98,7 @@ describe('retry', () => {
errors += 1;
throw 'bad';
}),
retry({ count: retries - 1, resetOnSuccess: true })
retry({ count: retries - 1, resetOnFirstValue: true })
)
.subscribe({
next() {
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('retry', () => {
return of(42);
}
}),
retry({ count: retries - 1, resetOnSuccess: true })
retry({ count: retries - 1, resetOnFirstValue: true })
)
.subscribe({
next(x: number) {
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('retry', () => {
return of(42);
}
}),
retry({ count: retries - 1, resetOnSuccess: false })
retry({ count: retries - 1, resetOnFirstValue: false })
)
.subscribe({
next(x: number) {
Expand Down
21 changes: 11 additions & 10 deletions src/internal/operators/retry.ts
Expand Up @@ -20,10 +20,10 @@ export interface RetryConfig {
*/
delay?: number | ((error: any, retryCount: number) => ObservableInput<any>);
/**
* Whether or not to reset the retry counter on success.
* Defaults to false.
* Whether or not to reset the retry counter when the retried subscription
* emits its first value.
*/
resetOnSuccess?: boolean;
resetOnFirstValue?: boolean;
}

/**
Expand Down Expand Up @@ -67,21 +67,22 @@ export interface RetryConfig {
* // "Error!: Retried 2 times then quit!"
* ```
*
* @param {number} count - Number of retry attempts before failing.
* @param {boolean} resetOnSuccess - When set to `true` every successful emission will reset the error count
* @param count - Number of retry attempts before failing.
* @param resetOnSuccess - When set to `true` every successful emission will reset the error count
* @return A function that returns an Observable that will resubscribe to the
* source stream when the source stream errors, at most `count` times.
*/
export function retry<T>(count?: number): MonoTypeOperatorFunction<T>;

/**
* A more configurable means of retrying a source.
* Returns an observable that mirrors the source observable unless it errors. If it errors, the source observable
* will be resubscribed to (or "retried") based on the configuration passed here. See documentation
* for {@link RetryConfig} for more details.
*
* If `delay` is provided as a `number`, after the source errors, the result will wait `delay` milliseconds,
* then retry the source. If `delay` is a function, th
* @param config The retry configuration
* @param config - The retry configuration
*/
export function retry<T>(config: RetryConfig): MonoTypeOperatorFunction<T>;

export function retry<T>(configOrCount: number | RetryConfig = Infinity): MonoTypeOperatorFunction<T> {
let config: RetryConfig;
if (configOrCount && typeof configOrCount === 'object') {
Expand All @@ -91,7 +92,7 @@ export function retry<T>(configOrCount: number | RetryConfig = Infinity): MonoTy
count: configOrCount,
};
}
const { count = Infinity, delay, resetOnSuccess = false } = config;
const { count = Infinity, delay, resetOnFirstValue: resetOnSuccess = false } = config;

return count <= 0
? identity
Expand Down

0 comments on commit 32ab5e2

Please sign in to comment.