Code Monkey home page Code Monkey logo

Comments (4)

constgen avatar constgen commented on June 27, 2024

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

from promise.

roysG avatar roysG commented on June 27, 2024

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.

from promise.

roysG avatar roysG commented on June 27, 2024

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.

from promise.

constgen avatar constgen commented on June 27, 2024

Any way it was not an issue of promises themselves. It is recommended to ask such questions in forums, Slack channels, etc.

from promise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.