Created
July 31, 2020 10:32
-
-
Save mishalrai/ff9c9826f246f522e33b3d3ba5a94159 to your computer and use it in GitHub Desktop.
This file contains 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
var arr = [1, 2, 3, 4, 5]; | |
var index = 0; | |
function sendRequest(){ | |
return new Promise( function(resolve, reject){ | |
index++; | |
console.log(arr[index], index); | |
if( 5 ==arr[index]){ | |
resolve({ status: 200}); | |
} | |
resolve({status: 400}); | |
}); | |
} | |
var isSolarReindexComplete = function(){ | |
return new Promise( function(resolve, reject){ | |
(function pingRequest(){ | |
console.count(); | |
sendRequest().then( function(res){ | |
console.log(res, 'response from server'); | |
if(200 == res.status){ | |
resolve({status: 200, message: 'success :)'}); | |
return true; | |
} | |
setTimeout(pingRequest, 2000); | |
}) | |
})() | |
}); | |
}; | |
isSolarReindexComplete().then( function(res){ | |
console.log(res) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment