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

May I use global.Promise=require("bluebird") ? #1026

Closed
strrchr opened this issue Feb 28, 2016 · 9 comments
Closed

May I use global.Promise=require("bluebird") ? #1026

strrchr opened this issue Feb 28, 2016 · 9 comments

Comments

@strrchr
Copy link

strrchr commented Feb 28, 2016

global.Promise=require("bluebird");

Is it suitable to replace the v8's Promise implementation?

@benjamingr
Copy link
Collaborator

Yes, it is.

In general - the issue tracker is not the place to ask support questions - you can use the disqus comments in the docs, stack overflow or other support channels.

Since the answer wasn't obvious from the docs - please feel free to follow up with a docs pull request.

@benjamingr
Copy link
Collaborator

Caveat: Note that bluebird intentionally does not support direct promise subclassing. It is extremely rare to see this used in Node or in general. If someone ever asks for this (and in almost 3 years no one ever has) it can be considered.

@petkaantonov
Copy link
Owner

No subclassing

@wmertens
Copy link

I'm having issues with this, when I put Bluebird on global.Promise it is still the old Promise in another file that is loaded later. Using babel-register and babel-polyfill to get ES6 semantics, before loading Bluebird.

@vphantom
Copy link

@wmertens You might want to file a distinct issue with this. Sounds like a conflict between Babel's promises polyfill and Bluebird.

@phpnode
Copy link

phpnode commented May 24, 2016

some of babel's transformations turn code like this:

const foo = new Promise(resolve => resolve(true));

into

const foo = new corejs.Promise(resolve => resolve(true));

in which case obviously the global.Promise = assignment will have no effect. Likely this is what is happening here.

@vphantom
Copy link

vphantom commented May 24, 2016

Thanks @phpnode that makes a lot of sense. There are Babel tweaks like https://babeljs.io/docs/plugins/transform-async-to-module-method/ but that's for the async/await polyfill specifically, no override. According to https://github.com/babel/babel-loader the only way might be:

require('babel-runtime/core-js/promise').default = require('bluebird');

(I don't use Babel so I haven't tested this.)

@zowers
Copy link

zowers commented Aug 4, 2017

changing global.Promise has no effect on result type of async functions, see #1404

@halex2005
Copy link

Please, try to use npm i babel-preset-bluebird -D transformations: https://www.npmjs.com/package/babel-preset-bluebird
Hope this helps

maxlath referenced this issue in inventaire/inventaire Jan 3, 2020
The new version of level-party let us use a version of leveldb
with promises support, allowing to remove most of the former level/base logic.
That level/base module was further simplified to simply return the levelup db object,
giving access to the whole levelup API (see https://github.com/Level/levelup#api),
moving specific behaviors to level/utils.

A custom version of level-geospatial is used to be able to use promise
until that PR is merged richorama/level-geospatial#2
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

8 participants