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.

"You must pass a resolver function as the first argument to the promise constructor"

See original GitHub issue

Why is this a thing?

I have researched this a little bit and I can’t seem to find out why this is necessary at all. Can someone explain why you need to pass a function to the Promise constructor?

Is there some reason we cannot create a Promise or Deferred object that we will manually resolve at a later point?

For example, in jQuery, you can do the following, and it is extremely useful in multiple scenarios:

var deferred = new $.Deferred(); //works in jquery to give you a deferred object you can control manually

var deferred = new Promise(); //fails in the es6 Promise polyfill with the subject of this issue as an error msg.

Can we not perform a simple check on the Promise constructor, and return an object with a resolve and reject function if no function was passed? Why the need to wrap our functions in the promise constructor?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
petkaantonovcommented, May 28, 2014

Deferred is trivial to implement on top of the constructor:

function Deferred() {
    var d = {};
    d.promise = new Promise(function(resolve, reject) {
        d.resolve = resolve;
        d.reject = reject;
    });
    return d;
}
0reactions
SgtPookicommented, May 31, 2014

+1 @petkaantonov exactly, thank you. I completely forgot about this… my bad.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does the Promise constructor require a function that calls ...
Function object with two arguments resolve and reject . The first argument fulfills the promise, the second argument rejects it. We can call ......
Read more >
Promise() constructor - JavaScript - MDN Web Docs
The Promise() constructor is primarily used to wrap functions that do not already support promises.
Read more >
Re: SetSignaturePromise Error Cause - Google Groups
VM5312 qz-tray.js:42 TypeError: You must pass a resolver function as the first argument to the promise constructor at lib$rsvp$promise$$needsResolver ...
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
First, let us create a generic function that accepts a PokeAPI URL as argument and returns a Promise. If the API call is...
Read more >
Promises
isFunction(resolver)) { throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); } if (!
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