"You must pass a resolver function as the first argument to the promise constructor"
See original GitHub issueWhy 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:
- Created 10 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Deferred is trivial to implement on top of the constructor:
+1 @petkaantonov exactly, thank you. I completely forgot about this… my bad.