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
65
votes
5 answers

Catching Errors in JavaScript Promises with a First Level try ... catch

So, I want my first level catch to be the one that handles the error. Is there anyway to propagate my error up to that first catch? Reference code, not working (yet): Promise = require('./framework/libraries/bluebird.js'); function promise() { …
Kirk Ouimet
  • 27,280
  • 43
  • 127
  • 177
61
votes
1 answer

Koa / Co / Bluebird or Q / Generators / Promises / Thunks interplay? (Node.js)

I'm investigating building a web app in part with Koa, but I don't quite have a handle on the hows, whens, and whys of choosing between - and applying - the range of supportive "making async easier" technologies/approaches (listed below). Overall…
JLS
  • 691
  • 1
  • 6
  • 10
60
votes
1 answer

Is it possible to get stack traces across async/await boundaries using --harmony_async_await in Node 7?

We're experimenting with using --harmony_async_await in Node 7, and compared to transpiling with babel for async/await are missing the ability to have long stack traces (http://bluebirdjs.com/docs/api/promise.longstacktraces.html). Obviously, it…
james.haggerty
  • 1,170
  • 6
  • 10
57
votes
4 answers

Convert promise to bluebird

I found an existing library that uses promises, however it doesn't use bluebird. The library functions don't come with all the extra features bluebird does like .map() or .tap(). How do I convert a "normal" or "non-bluebird" promise to a bluebird…
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
47
votes
6 answers

How to extract data out of a Promise

I have a promise that returns data and I want to save that in variables. Is this impossible in JavaScript because of the async nature and do I need to use onResolve as a callback? Can I somehow use this (e.g. wrap it with async/await): const { foo,…
Tobias Mühl
  • 1,788
  • 1
  • 18
  • 30
47
votes
8 answers

How do I promisify the AWS JavaScript SDK?

I want to use the aws-sdk in JavaScript using promises. Instead of the default callback style: dynamodb.getItem(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.log(data); //…
Martin Kretz
  • 1,523
  • 2
  • 13
  • 20
45
votes
2 answers

How do I use Bluebird with Angular?

I tried using Angular with Bluebird promises: HTML:
{{name}} {{also}}
JS: // javascript var app = angular.module('HelloApp', []); app.controller("HomeController",…
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
43
votes
2 answers

Are nested catches within promises required?

We would like to reduce the number of catch blocks inside our promises. If we remove the nested catches, will exceptions bubble up to the parent catch? temporaryUserModel.findOne({email: req.body.email}) .then(tempUser => { if (tempUser)…
wayofthefuture
  • 8,339
  • 7
  • 36
  • 53
43
votes
1 answer

What is the promise disposer pattern?

I've read about the promise disposer pattern in several places but I can't figure out what it is. It was suggested to me to use it in code that looks like: function getDb(){ return myDbDriver.getConnection(); } var users =…
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
40
votes
3 answers

if-else flow in promise (bluebird)

This is a short version of my code. var Promise = require('bluebird'); var fs = Promise.promisifyAll(require("fs")); if (conditionA) { fs.writeFileAsync(file, jsonData).then(function() { return functionA(); }); } else { …
vinayr
  • 11,026
  • 3
  • 46
  • 42
40
votes
3 answers

Bluebird, promises and then()

I've been only using bluebird for a few days but I want to go over all my old code and promisify it :) My problem is that I still don't fully grasp the flow of then() commands. Consider these two…
Madd0g
  • 3,841
  • 5
  • 37
  • 59
36
votes
4 answers

Define empty Bluebird promise like in Q

With Q I can define a new promise with: var queue = q(); But with Bluebird if I do: var queue = new Promise(); I get: TypeError: the promise constructor requires a resolver function How can I get the same result that I had with Q? This is a…
Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160
32
votes
4 answers

How do you properly promisify request?

Bluebird promisifaction is a little magic, and request is quite a mess (it's a function which behaves as an object with methods). The specific scenario is quite simple: I have a request instance with cookies enabled, via a cookie jar (not using…
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
31
votes
2 answers

How do I handle errors with promises?

As a node programmer. I'm used to use "nodebacks" for handling errors in my code: myFn(param, function(err, data) { if (err){ //error handling logic } else { // business logic } }); When writing that function, I…
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
30
votes
1 answer

Bluebird Promise.all - multiple promises completed aggregating success and rejections

Someone brought up an interesting case today with bluebird, what is the best way to handle multiple promises where we're not interested in stopping on a given fulfillment or rejection but rather interested in inspecting the final result. An…
j03m
  • 5,195
  • 4
  • 46
  • 50