Feature request: Custom Promise constructor
See original GitHub issueAllow defining a Promise constructor instead of using globals. The current implementation requires using polyfills that use globals.
Example
axios.defaults.promise = PromisePolyfill;
axios.get('/foo');
or
var axios_instance = axios.create({
promise: PromisePolyfill
});
axios_instance.get('/foo');
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Promise() constructor - JavaScript - MDN Web Docs
The Promise() constructor is primarily used to wrap functions that do not already support promises.
Read more >Resolve Javascript Promise outside the Promise constructor ...
I think there should be a formal way to achieve this in the future. This feature is very powerful in my opinion as...
Read more >Build a JavaScript Promise | Skilled.dev
Your constructor will take a function as an argument that will resolve or reject the async function request new PromiseSimple((resolve, reject) => {})...
Read more >Promise() constructor - JavaScript
A function to be executed by the constructor, during the process of constructing the promiseObj . The executor is custom code that ties...
Read more >Learn JavaScript Promises by Building a Custom ...
js. Callback functions. It would be impractical if making an HTTP request blocked the code until we got a response. Even if it...
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
Hi @rubennorte, funny that I was working on a PR at the same time you were closing this issue. I’m glad to see that promises are now a native feature, but I still think there are reasons for making promises pluggable.
Thank you and the team for your work on axios and for your consideration.
+1 Here’s my use case: I use Bluebird on the server side. I also want to use axios on the server side for accessing some external REST APIs. However, since I’m on node 5, axios returns promises that work with the default Promise implementation, and I have to wrap them whenever I want to use
.map
or the like, which is common.My choices are to either patch the global Promise, or tell axios which promise library to use. I’d rather do the latter.