When is .then(success, fail) considered an antipattern for promises?

I had a look at the bluebird promise FAQ, in which it mentions that .then(success, fail) is an antipattern. I don’t quite understand its explanation as for the try and catch. What’s wrong with the following? some_promise_call() .then(function(res) { logger.log(res) }, function(err) { logger.log(err) }) It seems that the example is suggesting the following to … Read more

Are there still reasons to use promise libraries like Q or BlueBird now that we have ES6 promises? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago. Improve this question After Node.js added native support for promises, are there still reasons to use libraries like Q … Read more

Aren’t promises just callbacks?

I’ve been developing JavaScript for a few years and I don’t understand the fuss about promises at all. It seems like all I do is change: api(function(result){ api2(function(result2){ api3(function(result3){ // do work }); }); }); Which I could use a library like async for anyway, with something like: api().then(function(result){ api2().then(function(result2){ api3().then(function(result3){ // do work }); … Read more

What is the explicit promise construction antipattern and how do I avoid it?

I was writing code that does something that looks like: function getStuffDone(param) { | function getStuffDone(param) { var d = Q.defer(); /* or $q.defer */ | return new Promise(function(resolve, reject) { // or = new $.Deferred() etc. | // using a promise constructor myPromiseFn(param+1) | myPromiseFn(param+1) .then(function(val) { /* or .done */ | .then(function(val) { … Read more

How do I access previous promise results in a .then() chain?

I have restructured my code to promises, and built a wonderful long flat promise chain, consisting of multiple .then() callbacks. In the end I want to return some composite value, and need to access multiple intermediate promise results. However the resolution values from the middle of the sequence are not in scope in the last … Read more

How do I convert an existing callback API to promises?

I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event: window.onload; // set to callback … window.onload = function() { }; 2. Plain callback: function request(onChangeHandler) { … } request(function() { // change happened … }); 3. Node style callback (“nodeback”): … Read more