Suppose I have scenario like this:
- Make request to post some data inside promise;
a) If response data is ok - finish Promise+then chain;
b) If response data is not ok - make new Promise+then chain - go back to point #2.
and code like this
var _p;
function make_promise(){
return new Promise(function(resolve, reject){
//get data
var data = 'some data';
resolve(data);
})
}
function handle_response(data) {
var _p;
if (data == 'some data'){
console.log(data);
//finish then chain
}
if (data != 'some data') {
_p = make_promise()
.then(handle_response);
}
}
_p = make_promise()
.then(handle_respone);
On each iteration when flow of execution goes on b)
choise this code will create new promise inside handle_response
function.
Will this new promise replace old or it will saved in closure?
If new promise will be saved in closure how to avoid this? Not save new promise to _p variable?