I'm trying to call a promise function from it's own response in this kind of pattern:
f().then(function(response){
if(response){
f(response).then(function(response){
if(response){
f(response).then.....
}
});
}
});
I'm working with angularjs. Thanks.
P.S.:
This examples are working but the third:
FIRST EXAMPLE: working:
var a = ['one','two','four'];
angular.forEach(a, function(number){
f(number).then(function(response){
console.log(response);
});
});
SECOND EXAMPLE: working:
var a = ['one','two','four'];
angular.forEach(a, function(number){
f(number).then(function(response){
if(response){
f(response).then(function(response2){
if(response2){
f(response2).then(function(response3){
console.log(response3); //this is the behaviour I'm trying to automate
});
}
});
}
});
});
THIRD EXAMPLE: not working:
var a = ['one','two','four'];
angular.forEach(a, function(number){
var t = '';
f(number).then(function(response){
t = response;
while(t != ''){
f(t).then(function(response){
console.log(response);
t = response;
});
}
});
});
At the end I did so:
var a=['one','two','four'];
var simple = function(token){
getasync(a[a.length-1], token).then(function(resptoken){
console.log(resptoken);
if(resptoken)
simple(resptoken);
else if (a.length>1){
a.pop() ;
simple(resptoken);
}else{
console.log("theend");
}
});
}