function getItem(key){
return new Promise(function(resolve, reject){
if( key === "property" ){
var delay = Math.random() * 10000;
console.log( "Property Code Delay ", delay );
setTimeout(function(){ resolve("PropertyCode");}, delay );
} else if( key === "customer" ){
var delay = Math.random() * 5000;
console.log( "Customer Code Delay ", delay );
setTimeout(function(){ resolve("customerCode");}, delay );
}
});
}
function getDefaultParams(){
return new Promise(function(resolve, reject){
var result = {
propertyCode : null,
customerCode : null
};
var chain = [ getItem("property"), getItem("customer")];
Promise.all(chain).then(function(values){
result.propertyCode = values[0];
result.customerCode = values[1];
resolve(result);
});
});
}
function get(){
getDefaultParams().then(function(param){
console.log( "Construct URL" );
console.log(param);
console.log( "Call Get with ", param );
});
}
get();