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

What’s the difference between returning value or Promise.resolve from then()

What is the difference between: new Promise(function(res, rej) { res(“aaa”); }) .then(function(result) { return “bbb”; }) .then(function(result) { console.log(result); }); and this: new Promise(function(res, rej) { res(“aaa”); }) .then(function(result) { return Promise.resolve(“bbb”); }) .then(function(result) { console.log(result); }); I’m asking as I’m getting different behaviour Using Angular and $http service with chaining .then(). A bit too … Read more

Resolve promises one after another (i.e. in sequence)?

Consider the following code that reads an array of files in a serial/sequential manner. readFiles returns a promise, which is resolved only once all files have been read in sequence. var readFile = function(file) { … // Returns a promise. }; var readFiles = function(files) { return new Promise((resolve, reject) => { var readSequential = … 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