I hereby claim:
- I am nadersl on github.
- I am nedsl (https://keybase.io/nedsl) on keybase.
- I have a public key ASA32BJXSbCaRrpssslIKdootbi5-_GPguOq9uIU9LcQXAo
To claim this, I am signing this object:
| import PromiseInsist from '..'; | |
| class GoodluckError extends Error { | |
| constructor(msg: string, errorCode: number) { | |
| super(msg); | |
| this.errorCode = errorCode; | |
| Object.setPrototypeOf(this, GoodluckError.prototype); | |
| } | |
| private errorCode: number; | |
| public getErrorCode() { |
| Attempt #29 done in 0 ms | |
| Retrying t1 after 2000 ms | |
| Attempt #28 done in 0 ms | |
| Retrying t1 after 2000 ms | |
| Attempt #27 done in 0 ms | |
| Retrying t1 after 2000 ms | |
| Canceled task of ID : t1 (~ 4556 ms) | |
| Retrying t2 after 2000 ms | |
| t1: Error: Random magic number wasn't guessed. | |
| Retrying t2 after 2000 ms |
| import PromiseInsist, { Delays, ErrorFilters } from 'promise-insist'; | |
| import axios from 'axios'; | |
| // A preset of Delays error filters. | |
| const { ExponentialDelay } = Delays; | |
| //A Preset of Axios error filters. | |
| const { isRetryable, isServerError, isNetError, isSafe, isIdempotent } = ErrorFilters.AxiosErrorFilters; | |
| //Create an Axios PromiseInsist instance with 20 retries per request , exponential delay and only retry if error is a server error. | |
| const { |
| npm i promise-insist --save |
| import PromiseInsist, { Delays, ErrorFilters } from '.'; | |
| import axios from 'axios'; | |
| // A preset of Delays error filters. | |
| const { ExponentialDelay } = Delays; | |
| //A Preset of Axios error filters. | |
| const { isRetryable, isServerError, isNetError, isSafe, isIdempotent } = ErrorFilters.AxiosErrorFilters; | |
| const { | |
| insist, | |
| cancelInsist | |
| } = new PromiseInsist({ retries: 20, delay: ExponentialDelay(), errorFilter: (isRetryable) }) |
| async function runTest() { | |
| try { | |
| const resp = await insist(() => axios.get('http://localhost:1337')) | |
| console.log(resp) // We got it! | |
| } catch (err) { console.log(err); } //error thrown after all retries been consumed. | |
| } |
| async function runTest() { | |
| try { | |
| insist( | |
| () => axios.get('http://localhost:1337'), | |
| //onRetry callback with current attempt count and timeconsumed per this task passed. | |
| (attemptCount, timeConsumed) => { console.log(`Attempt #${attemptCount} done in ${timeConsumed} ms`); }, | |
| {// Specify custome config per this insist | |
| delay: 2000, | |
| retries: 10, | |
| errorFilter: isServerError |
| async function runCancelTest() { | |
| try { | |
| const task = insist(() => axios.get('http://localhost:1337')); | |
| setTimeout(() => cancelInsist(task), 2000); //cancel task after 2 seconds | |
| const resp = await task; //this awaited task shall complete in 2 seconds if it was still retrying | |
| } catch (err) { console.log(err); } | |
| } |
| async function runReplaceTaskTest() { | |
| try { | |
| const task = insist(() => axios.get('http://localhost:1337')); | |
| setTimeout(() => replaceTask(task,() => axios.get('http://api.someSite.com')), 2000); | |
| const resp = await task; | |
| } catch (err) { console.log(err); } | |
| } |
I hereby claim:
To claim this, I am signing this object: