JSFiddle - React, Tailwind, and code Playground

by donniec

JavaScript

var urls = ["a", "b", "c", "d", "e", "f", "g"];

urls.reduce(function(chain, item){
    return chain
    .then(function(urlA){
        console.log(urlA+ " has been accepted ");
        return urlA;
    },
    function(){
        console.log("attempting to fetch "+item);
        return fetch(item);
    });
},
Promise.reject())
.then(function(url){
    console.log("url "+url+" was good.");
});

function fetch(url){
	return new Promise(function(resolve, reject){
		if(url == "c"){
			resolve(url);
		}
		else {
			reject(url);
		}
	});
}