mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-09-07 17:50:19 +00:00
p-retry: Update for v2.0
This commit is contained in:
Vendored
+11
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user