Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve and reject returned from .defer() are not bound to promise #1678

Open
rauno56 opened this issue Apr 20, 2021 · 0 comments
Open

resolve and reject returned from .defer() are not bound to promise #1678

rauno56 opened this issue Apr 20, 2021 · 0 comments

Comments

@rauno56
Copy link

rauno56 commented Apr 20, 2021

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

  2. What platform and version? All

  3. Did this issue happen with earlier version of bluebird? Not sure.

Using (deprecated) defer API and passing resolve anywhere without having a promise with it results in an error:

     Uncaught TypeError: Cannot read property 'promise' of undefined
      at deferResolve (node_modules/bluebird/js/release/promise.js:754:32)
      at Timeout._onTimeout (test/index.test.ts:108:7)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

That's where resolve and reject are defined:

function deferResolve(v) {this.promise._resolveCallback(v);}
function deferReject(v) {this.promise._rejectCallback(v, false);}

To reproduce

const bluebird = require('bluebird');
const {
  promise,
  resolve,
} = bluebird.defer();
resolve();
/*
Uncaught:
TypeError: Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.

    See http://goo.gl/sdkXL9

    at PromiseResolver.resolve.PromiseResolver.fulfill (/home/rauno/projects/bluebird/node_modules/bluebird/js/main/promise_resolver.js:88:15)
*/

Running only this example actually surprisingly gives me a different error from what I previously saw in the wild.

Would you consider accepting a patch that binds the callbacks to the promise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant