I am attempting to use JavaScript promises in a project and the order of events are unexpected. I have narrowed it down into a small demo using a test promise. And then I call it like so: This is the console output: How can I get an output of: Answer .then() expects a function reference. When you do something like
Tag: promise
Is there a way to short circuit async/await flow?
All four functions are called below in update return promises. What if we want to abort the sequence from outside, at any given time? For example, while fetchMetaData is being executed, we realize we no longer need to render the component and we want to cancel the remaining operations (fetchContent and render). Is there a way to abort/cancel these operations
Why does .json() return a promise?
I’ve been messing around with the fetch() api recently, and noticed something which was a bit quirky. post.data returns a Promise object. http://jsbin.com/wofulo/2/edit?js,output However if it is written as: post here is a standard Object which you can access the title attribute. http://jsbin.com/wofulo/edit?js,output So my question is: why does response.json return a promise in an object literal, but return the
Using loops and promises in transactions in Sequelize
I am currently building a Nodejs, Express, Sequelize (w. PostgreSQL) app, and have run into a few problems with using promises together with transactions and loops. I am trying to figure out how to use a for loops in a transaction. I am trying to loop through a list of members and create a new user in the database for
JS Promises: Fulfill vs Resolve
I understand Promises to exist in one of three states: A Promise can either be pending (unresolved), fulfilled (resolved successfully) or rejected (resolved unsuccessfully). Reading through the A+ Promise Spec and MDN’s documentation, I am confused that they both acknowledge the fulfilled and rejected states but in the definition of the Promise constructor they specify two callbacks: resolve and reject.
How to pass parameter to a promise function
this might seem a silly question but I am a newbie in this topic. I am working on promises on node js. And I want to pass parameter to a promise function. However I could not figure it out. and the function is something like Answer Wrap your Promise inside a function or it will start to do its job
chain promises in javascript
I’ve created many promises like that, in order to create object in my database. At the end, I want call all my promises in the order I want. (because somes object depend of other, so I need to keep that order) So I expect to see : Unfortunately, this messages are shuffled and I don’t understand what. Thanks Answer Looks
JavaScript Promises – reject vs. throw
I have read several articles on this subject, but it is still not clear to me if there is a difference between Promise.reject vs. throwing an error. For example, Using Promise.reject Using throw My preference is to use throw simply because it is shorter, but was wondering if there is any advantage of one over the other. Answer There is
How can I fetch an array of URLs with Promise.all?
If I have an array of urls: And I want to build an object that looks like this: I’ve been trying to learn to do this with fetch, which of course returns Promises. Some things I’ve tried that don’t work: This doesn’t look right, and in any case it doesn’t work — I don’t end up with an array [‘one’,
Use Promise to wait until polled condition is satisfied
I need to create a JavaScript Promise that will not resolve until a specific condition is true. Let’s say I have a 3rd party library, and I need to wait until a certain data condition exists within that library. The scenario I am interested in is one where there is no way to know when this condition is satisfied other