Created
January 18, 2017 23:54
-
-
Save anonymous/fc437c9f9970b060f006b826e439e86b to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/toqaka
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
<div id="root"></div> | |
<script id="jsbin-javascript"> | |
function requestMaker(data) { | |
return new Promise(function(fulfill, reject) { | |
setTimeout(function(){ | |
fulfill(data); | |
},3000); | |
}); | |
} | |
function requestFactory(data){ | |
return new Promise(function(fulfill, reject){ | |
setTimeout(function(){ | |
if(data === "Gianna" || data === "Lisa"){ | |
fulfill ("done"); | |
} else{ | |
fulfill (requestMaker(data)); | |
} | |
},5000); | |
}); | |
} | |
function main(){ | |
var Arr = ["Echo","Sofia","Gianna","Kayla","Lisa"]; | |
var final = []; | |
for(var key in Arr){ | |
requestFactory(Arr[key]).then(function(ret){ | |
final.push(ret); | |
console.log("array state:"); | |
console.log(final); | |
}); | |
} | |
Promise.all(Arr.map(name => requestFactory(name))).then(result => console.log(result)); | |
return final; | |
} | |
window.onload = function() { | |
main(); | |
}; | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function requestMaker(data) { | |
return new Promise(function(fulfill, reject) { | |
setTimeout(function(){ | |
fulfill(data); | |
},3000); | |
}); | |
} | |
function requestFactory(data){ | |
return new Promise(function(fulfill, reject){ | |
setTimeout(function(){ | |
if(data === "Gianna" || data === "Lisa"){ | |
fulfill ("done"); | |
} else{ | |
fulfill (requestMaker(data)); | |
} | |
},5000); | |
}); | |
} | |
function main(){ | |
var Arr = ["Echo","Sofia","Gianna","Kayla","Lisa"]; | |
var final = []; | |
for(var key in Arr){ | |
requestFactory(Arr[key]).then(function(ret){ | |
final.push(ret); | |
console.log("array state:"); | |
console.log(final); | |
}); | |
} | |
Promise.all(Arr.map(name => requestFactory(name))).then(result => console.log(result)); | |
return final; | |
} | |
window.onload = function() { | |
main(); | |
};</script></body> | |
</html> |
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
function requestMaker(data) { | |
return new Promise(function(fulfill, reject) { | |
setTimeout(function(){ | |
fulfill(data); | |
},3000); | |
}); | |
} | |
function requestFactory(data){ | |
return new Promise(function(fulfill, reject){ | |
setTimeout(function(){ | |
if(data === "Gianna" || data === "Lisa"){ | |
fulfill ("done"); | |
} else{ | |
fulfill (requestMaker(data)); | |
} | |
},5000); | |
}); | |
} | |
function main(){ | |
var Arr = ["Echo","Sofia","Gianna","Kayla","Lisa"]; | |
var final = []; | |
for(var key in Arr){ | |
requestFactory(Arr[key]).then(function(ret){ | |
final.push(ret); | |
console.log("array state:"); | |
console.log(final); | |
}); | |
} | |
Promise.all(Arr.map(name => requestFactory(name))).then(result => console.log(result)); | |
return final; | |
} | |
window.onload = function() { | |
main(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment