Skip to content
Advertisement

Tag: promise

Why are Javascript promises resolving out of order?

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

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

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.

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

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

Advertisement