Skip to content

Instantly share code, notes, and snippets.

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