p-retry: Update for v2.0

This commit is contained in:
Alex Van Camp
2018-08-10 17:18:08 -05:00
parent c9f9d46d4b
commit 8aad19dfb1
2 changed files with 17 additions and 3 deletions
+11 -2
View File
@@ -1,4 +1,4 @@
// Type definitions for p-retry 1.0
// Type definitions for p-retry 2.0
// Project: https://github.com/sindresorhus/p-retry#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -8,7 +8,7 @@ import { OperationOptions } from 'retry';
export = pRetry;
declare function pRetry<T>(input: (attemptCount: number) => PromiseLike<T> | T, options?: OperationOptions): Promise<T>;
declare function pRetry<T>(input: (attemptCount: number) => PromiseLike<T> | T, options?: pRetry.Options): Promise<T>;
declare namespace pRetry {
class AbortError extends Error {
@@ -16,4 +16,13 @@ declare namespace pRetry {
readonly originalError: Error;
constructor(message: string | Error);
}
interface FailedAttemptError extends Error {
attemptNumber: number;
attemptsLeft: number;
}
interface Options extends OperationOptions {
onFailedAttempt?: (error: FailedAttemptError) => void;
}
}
+6 -1
View File
@@ -11,6 +11,11 @@ const run = () => fetch('https://sindresorhus.com/unicorn')
return response.text();
});
pRetry(run, {retries: 5}).then(result => {
pRetry(run, {
retries: 5,
onFailedAttempt: error => {
console.log(`Attempt ${error.attemptNumber} failed. There are ${error.attemptsLeft} attempts left.`);
}
}).then(result => {
const str: string = result;
});