Skip to content

Instantly share code, notes, and snippets.

@wayspurrchen
Created May 29, 2015 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayspurrchen/5faf2164f7e27a65f0a0 to your computer and use it in GitHub Desktop.
Save wayspurrchen/5faf2164f7e27a65f0a0 to your computer and use it in GitHub Desktop.
Promise retry
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