Created
May 29, 2015 16:11
-
-
Save wayspurrchen/5faf2164f7e27a65f0a0 to your computer and use it in GitHub Desktop.
Promise retry
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
function retry ( promiseToRetry, maxRetries ) { | |
return new Promise( function ( resolve, reject ) { | |
promiseToRetry.then( function ( resolve ) { | |
resolve( result ); | |
} ).catch( function ( e ) { | |
if ( maxRetries > 0 ) { | |
return retry( promiseToRetry, maxRetries - 1 ); | |
} else { | |
reject( e ) | |
} | |
} ); | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment