mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
Update OperationOptions to accept an array of timeouts in the retry module (#59861)
* Update OperationOptions to accept an array of timeouts in the retry module * Update async-retry typings accordingly * Add new test for promise-retry
This commit is contained in:
4
types/async-retry/index.d.ts
vendored
4
types/async-retry/index.d.ts
vendored
@@ -6,7 +6,7 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { OperationOptions } from 'retry';
|
||||
import { WrapOptions } from 'retry';
|
||||
|
||||
declare function AsyncRetry<A>(
|
||||
fn: AsyncRetry.RetryFunction<A>,
|
||||
@@ -14,7 +14,7 @@ declare function AsyncRetry<A>(
|
||||
): Promise<A>;
|
||||
|
||||
declare namespace AsyncRetry {
|
||||
interface Options extends OperationOptions {
|
||||
interface Options extends WrapOptions {
|
||||
onRetry?: ((e: Error, attempt: number) => any) | undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,4 +90,29 @@ describe("Promise-retry tests", () => {
|
||||
.then((value: any) => console.log("Finished with value ", value))
|
||||
.catch((err: any) => console.error(err.message || err));
|
||||
});
|
||||
|
||||
it('should allow an array of timeouts as the param', () => {
|
||||
let count = 0;
|
||||
|
||||
promiseRetry(
|
||||
(retryCb, attemptNumber) => {
|
||||
count += 1;
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
console.log("Count in then()", count);
|
||||
if (count > 1) return Promise.resolve('final');
|
||||
else return Promise.reject(new Error('arbitrary excuse to retry'));
|
||||
})
|
||||
.catch((err: any) => {
|
||||
console.log("Count in catch()", count);
|
||||
if (count > 1) return Promise.resolve('final');
|
||||
else return retryCb(err);
|
||||
});
|
||||
},
|
||||
[2000, 3000, 4000]
|
||||
)
|
||||
.then((value: any) => console.log("Finished with value ", value))
|
||||
.catch((err: any) => console.error(err.message || err));
|
||||
});
|
||||
});
|
||||
|
||||
6
types/retry/index.d.ts
vendored
6
types/retry/index.d.ts
vendored
@@ -80,7 +80,9 @@ export interface AttemptTimeoutOptions {
|
||||
*/
|
||||
export function operation(options?: OperationOptions): RetryOperation;
|
||||
|
||||
export interface OperationOptions extends TimeoutsOptions {
|
||||
export type OperationOptions = WrapOptions | number[];
|
||||
|
||||
export interface WrapOptions extends TimeoutsOptions {
|
||||
/**
|
||||
* Whether to retry forever.
|
||||
* @default false
|
||||
@@ -148,4 +150,4 @@ export interface CreateTimeoutOptions {
|
||||
*
|
||||
*/
|
||||
export function wrap(object: object, methods?: string[]): void;
|
||||
export function wrap(object: object, options?: OperationOptions, methods?: string[]): void;
|
||||
export function wrap(object: object, options?: WrapOptions, methods?: string[]): void;
|
||||
|
||||
@@ -63,6 +63,9 @@ operation.stop();
|
||||
operation.reset();
|
||||
operation.attempts(); // $ExpectType number
|
||||
|
||||
// accept an array of timeouts as well:
|
||||
retry.operation([2000, 3000, 4000]);
|
||||
|
||||
retry.createTimeout(att); // $ExpectType number
|
||||
retry.createTimeout(att, createTimeoutOptions); // $ExpectType number
|
||||
|
||||
|
||||
Reference in New Issue
Block a user