Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let myArray = [1,3,23,5,6,7,8,8];
- let myCounter = 1;
- function myPromise() {
- return new Promise((resolve, reject) => {
- try {
- fetch('https://test-site.ru')
- .then((response) => {
- return response.text();
- })
- .then((data) => {
- resolve(myCounter+=1);
- });
- }
- catch (err) {
- reject(err);
- }
- });
- };
- function testPromise() {
- myPromise().then((myCounter) => {
- if (myArray.length>myCounter) {
- setTimeout(function(){
- testPromise();
- }, 500)
- };
- });
- };
- testPromise();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement