question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent behavior of execution when using multiple copies of bluebird

See original GitHub issue
  1. What version of bluebird is the issue happening on?

v3.5.1

  1. What platform and version? (For example Node.js 0.12 or Google Chrome 32)

Node.js 6.8.1 & Node.js 8.11.1

  1. Did this issue happen with earlier version of bluebird?

It also happens with bluebird v3.4.7

To replicate:

  1. mkdir bluebird-test
  2. cd bluebird-test
  3. npm init --yes
  4. npm i bluebird --save
  5. cp -r ./node_modules/bluebird ./node_modules/bluebird2
  6. touch index.js
  7. copy & paste the following into the index.js
  8. node index.js
const Promise = require('bluebird');
const Promise2 = require('bluebird2');

function second() {
    console.log('SECOND');
}

function start() {
    return new Promise(function(resolve, reject) {

        process.nextTick(tick);

        function tick() {
            return setup().catch(function(err) {
                console.log('FIRST');
            });
        }
    });
}

function setup() {
    return Promise.resolve().then(function() {
        //Promise2 executes/is handled differently
        return Promise2.map([1], function() {
            process.nextTick(function() {
                second();
            });
            throw new Error('test error');
        });
    });
}

return start();

stdout:

SECOND
FIRST

expected stdout:

FIRST
SECOND

When only a single bluebird package is used as in the script bellow, I get the expected output;

const Promise = require('bluebird');

function second() {
    console.log('SECOND');
}

function start() {
    return new Promise(function(resolve, reject) {

        process.nextTick(tick);

        function tick() {
            return setup().catch(function(err) {
                console.log('FIRST');
            });
        }
    });
}

function setup() {
    return Promise.resolve().then(function() {
        return Promise.map([1], function() {
            process.nextTick(function() {
                second();
            });
            throw new Error('test error');
        });
    });
}

return start();

This is the case when some dependent npm package requires different version of bluebird or simply project’s dependencies are not flatten out. Understandably this breaks things.

Despite that, Thank you for the amazing library!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
benjamingrcommented, Jun 21, 2018

What’s the implementation reason behind NOT returning the original promise object for object that isAnyBluebirdPromise as it is done:

It might be a different version of bluebird and not contain the same methods - for example Bluebird 2 and Bluebird 3.

0reactions
foginecommented, Jun 21, 2018

Bluebird instances identify each other and do a performance optimization where they don’t need to do the whole ResolveThenableJob dance they need to with native promises.

What’s the implementation reason behind NOT returning the original promise object for object that isAnyBluebirdPromise as it is done: https://github.com/petkaantonov/bluebird/blob/49da1ac256c7ee0fb1e07679791399f24648b933/src/thenables.js#L10

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise.map concurrency execution order · Issue #708
I am having a problem with the concurrency option for Promise.map. ... This is unintuitive and inconsistent with the behavior of ES6 map...
Read more >
Synchronous promise resolution (bluebird vs. jQuery)
In both cases (synchronous with cast or asynchronous resolution), you'll have the correct execution order. Note that having a function being ...
Read more >
Bluebird: High-performance SDN for Bare-metal Cloud ...
In the Bluebird model, we collapse two key roles into a single device: 1) logical net- work isolation between customers via Virtual Routing...
Read more >
Breeding Season Aggression of Female and Male Eastern ...
Naturally occurring aggression between female eastern bluebirds (Sialia sialis) is dramatic, resulting in severe injuries and even death.
Read more >
How to succeed on the pursuit of a PhD
Executing the next actions in efficient batches. The book elaborates on all these steps in more detail, but it could have been written...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found