Skip to content

When using .return on a thenable, the .then function gets called too early #1210

@not-an-aardvark

Description

@not-an-aardvark

Please answer the questions the best you can:

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

3.4.3

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

Node.js v6.4.0

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

No; this only happens since v3.4.2.


Reproduction code:

var Promise = require('bluebird');

var myObject = {
  then: function() { console.log('.then was called'); }
};

var promiseForMyObject = Promise.delay(5000).then(function() {
  // myObject happens to have a .then function, but we don't actually want it to be treated as a thenable.
  // As a workaround, just get rid of the .then function.
  myObject.then = undefined;
}).return(myObject)
  .then(function() {
    console.log('promiseForMyObject fulfilled');
  });

Output in <= v3.4.1:

(after 5 seconds): promiseForMyObject fulfilled

Output in v3.4.2 and v3.4.3:

(immediately): .then was called

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions