promise-retry: add a retry function to abort early

This commit is contained in:
Girish Ramakrishnan
2022-01-06 11:05:08 -08:00
parent bf51bc25e9
commit c74556fa3b
2 changed files with 12 additions and 0 deletions
+11
View File
@@ -35,4 +35,15 @@ describe('promiseRetry', function () {
expect(result).to.be(42);
});
it('can abort with 1 try only', async function () {
let tryCount = 0;
const [error] = await safe(promiseRetry({ times: 5, interval: 1000, retry: () => false }, async () => {
++tryCount;
throw tryCount;
}));
expect(tryCount).to.be(1);
expect(error).to.be(1);
});
});