2.0.3 • Published 4 years ago

@jakedeichert/promise-repeater v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

promise-repeater build status

⏰ Repeat promises until they resolve successfully or hit the maximum attempt limit

Installation

npm install @jakedeichert/promise-repeater

Usage

import { repeat } from '@jakedeichert/promise-repeater';

// Create an async/promise function that you want to attempt multiple times.
const promiseFunc = async () => {
    if (Math.random() < 0.5) throw new Error();
    return 'success';
};


// Repeat this promise until it resolves or hits the maximum attempt limit.
// This example will reject after 5 attempts.
const val1 = await repeat(promiseFunc).maxAttempts(5).start();


// You can also specify a delay (ms) between attempts.
// This example waits 1 second between attempts.
const val2 = await repeat(promiseFunc).maxAttempts(5).delay(1000).start();


// You could also attempt an infinite amount of times.
const val3 =  await repeat(promiseFunc).unlimitedAttempts().delay(1000).start();

Try this out on RunKit

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago