Closed roysG closed 7 years ago
It works as expected. Every call of roy()
gives a new instance of a Promise. So on the first call it returns a new Promise that will never be resolved because condition will never call else
statement. num
is a local variable. It is not persisted anywhere and destroyed after roy()
is called. A Promise will be resolved only in case when you pass a positive number to roy(number)
. There is defiantly an issue in the logic.
What is your expected result? If you want this to be resolved
roy().then(x=>{
console.log('x:',x);
})
then remove this
if(!num)
roy(num+1);
else
Hi @constgen, I just give an example for load more items. Lets say example for load more likes of instagram post, till you get end.
So in this case you will need to call again to same function but with another next_token.
The problem, when you will finish iterate all likes and then go out to your resolve you will find yourself stuck in pending mode.
What i am trying to figure out, how can i go to .then function, when i need to call again to the same function.
Hopefully i succeed to explain myself better.
For those who have also problem like me, i solved the problem with using create new function with name: "loadMore", inside the promise. In the "loadMore" i call again the request i need.
Any way it was not an issue of promises themselves. It is recommended to ask such questions in forums, Slack channels, etc.
I call to "roy" function and then i call again to the same function, but in the second time i call to my resolve, but resolve it not back and instead it stuck on "pending" state.
Console:
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined} proto : Promise [[PromiseStatus]] : "pending" [[PromiseValue]] : undefined