Skip to content

Instantly share code, notes, and snippets.

@wayspurrchen
Created May 29, 2015 16:11
Embed
What would you like to do?
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