Suppose I have this function below:
var a = 0;
function test () {
return new Promise(function (resolve, reject) {
a++;
if (a < 10) {
test()
reject(a)
} else {
resolve(a)
}
})
}
test().then(function (a) {
console.log('resolve', a)
}).catch(function (a) {
console.log('reject', a)
})
It prints:
reject 10
I expect that it will print reject 1 ... 10.
How can I achieve this?