Last active
May 23, 2016 17:47
-
-
Save chekit/47a4786e11efedfeb6eb477374f43c73 to your computer and use it in GitHub Desktop.
Gets an array values consistently, read them and resolve with results (this is a basic example that was done to understand how I can read array, make an ajax call with value and resolve for getting next one). The values are printing in arow.
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
'use strict'; | |
//The sandbox http://jsbin.com/leraku/edit?js,console | |
let mas = [1, 2, 3]; | |
let prom = function (value) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
console.log(value); | |
resolve(); | |
}, 400); | |
}); | |
} | |
let seq = function (arr) { | |
let ind = 0; | |
function next () { | |
if (ind < arr.length) { | |
prom(arr[ind++]) | |
.then(next); | |
} | |
} | |
next(); | |
} | |
seq(mas); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment