Questions tagged [bluebird]

Bluebird is a fully featured promise library for client and server JavaScript with focus on innovative features and performance.

Bluebird is a fully featured promise library for client and server JavaScript code with focus on innovative features and performance.

Bluebird is known for its fast performance, context binding, and long stack traces. It offers very fast coroutine support that emulates C#'s async/await statement.

Bluebird's promise system also cures JavaScript's callback problem.

It is a fully A+ spec compliant implementation.

Bluebird supports both Node.js and browsers (with Browserify and directly).

1871 questions
860
votes
24 answers

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) { …
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
748
votes
17 answers

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…
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
647
votes
3 answers

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…
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
507
votes
11 answers

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 …
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
498
votes
19 answers

How to check if an object is a Promise?

Whether it's an ES6 Promise or a Bluebird Promise, Q Promise, etc. How do I test to see if a given object is a Promise?
theram
  • 5,503
  • 2
  • 13
  • 14
253
votes
1 answer

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

After Node.js added native support for promises, are there still reasons to use libraries like Q or BlueBird? For example if you are starting a new project and let's assume in this project you don't have any dependencies that use these libraries,…
Murat Ozgul
  • 11,193
  • 6
  • 29
  • 32
233
votes
7 answers

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) {…
user2127480
  • 4,623
  • 5
  • 19
  • 17
175
votes
9 answers

How to promisify Node's child_process.exec and child_process.execFile functions with Bluebird?

I'm using the Bluebird promise library under Node.js, it's great! But I have a question: If you take a look at the documentation of Node's child_process.exec and child_process.execFile you can see that both of these functions are returning a…
Zoltan
  • 2,631
  • 2
  • 17
  • 13
174
votes
2 answers

Placement of catch BEFORE and AFTER then

I have trouble understanding the difference between putting .catch BEFORE and AFTER then in a nested promise. Alternative 1: test1Async(10).then((res) => { return test2Async(22) .then((res) => { return test3Async(100); }).catch((err)…
Zanko
  • 4,298
  • 4
  • 31
  • 54
169
votes
4 answers

How does Bluebird's util.toFastProperties function make an object's properties "fast"?

In Bluebird's util.js file, it has the following function: function toFastProperties(obj) { /*jshint -W027*/ function f() {} f.prototype = obj; ASSERT("%HasFastProperties", true, obj); return f; eval(obj); } For some reason,…
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
160
votes
1 answer

What is the equivalent of Bluebird Promise.finally in native ES6 promises?

Bluebird offers a finally method that is being called whatever happens in your promise chain. I find it very handy for cleaning purposes (like unlocking a resource, hiding a loader, ...) Is there an equivalent in ES6 native promises?
Aric Lasry
  • 1,769
  • 3
  • 11
  • 11
153
votes
8 answers

Handling multiple catches in promise chain

I am still fairly new to promises and am using bluebird currently, however I have a scenario where I am not quite sure how to best deal with it. So for example I have a promise chain within an express app like…
Grofit
  • 17,693
  • 24
  • 96
  • 176
132
votes
2 answers

Promise.resolve vs new Promise(resolve)

I'm using bluebird and I see two ways to resolve synchronous functions into a Promise, but I don't get the differences between both ways. It looks like the stacktrace is a little bit different, so they aren't just an alias, right? So what is the…
Pipo
  • 5,623
  • 7
  • 36
  • 46
120
votes
13 answers

Correct way to write loops for promise.

How to correctly construct a loop to make sure the following promise call and the chained logger.log(res) runs synchronously through iteration? (bluebird) db.getUser(email).then(function(res) { logger.log(res); }); // this is a promise I tried the…
user2127480
  • 4,623
  • 5
  • 19
  • 17
70
votes
1 answer

How to chain and share prior results with Promises

I'm using the bluebird library and need to make a series of HTTP requests and need to some of the response data to the next HTTP request. I've built a function that handles my requests called callhttp(). This takes a url and the body of a POST. I'm…
user1513388
  • 7,165
  • 14
  • 69
  • 111
1
2 3
99 100