Created
March 5, 2017 22:40
-
-
Save vinicius73/98b47d0998cc7de6ea932ab83f5a2252 to your computer and use it in GitHub Desktop.
tries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { identity } from 'lodash' | |
import waith from './waith' | |
export default (action, repetitions, timeToWaith = 3000) => { | |
const onError = counter => () => { | |
if (counter < repetitions) { | |
return run(counter + 1) | |
} | |
return Promise.reject(new Error('TRIES_FAILURE')) | |
} | |
const run = counter => waith(timeToWaith) | |
.then(action) | |
.then(identity, onError(counter)) | |
return run(1) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (time = 1000) => new Promise(resolve => setTimeout(resolve, time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment