cujojs / when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.
Other
3.44k stars 396 forks source link

ES6 shim without global Promise #451

Closed guybedford closed 9 years ago

guybedford commented 9 years ago

Is it possible to require the es6-shim in a way that doesn't override the global Promise?

briancavalier commented 9 years ago

Hey @guybedford. There's no way yet, but we're planning to provide one.

In the meantime, would it work for you to write your own tiny wrapper module that does the following?

var unhandledRejection = require('when/lib/decorators/unhandledRejection');
module.exports = unhandledRejection(require('when/lib/Promise'));

If so, then that'd get you an ES6 compliant Promise with the default unhandled rejection reports enabled, without overriding the global.

If that's not an option, let me know, and I'll bump up the priority on this.

guybedford commented 9 years ago

Thanks @briancavalier for the quick response - yes that will work great. Note it is specifically for Node that this is needed - in the browser we do want the Promise global to be polyfilled.

In terms of implementing the shim without overriding the global, what would be really useful is setting global.Promise only if it is not already set, and then perhaps providing a polyfill interface like global.when.Promise that could also be relied on, although that may not even be necessary.

briancavalier commented 9 years ago

yes that will work great

Cool, thanks for confirming.

what would be really useful is setting global.Promise only if it is not already set

Yep, I totally agree. That's the route we'll go. See #442 for a bit more on why we originally decided to forcibly overwrite global Promise.

briancavalier commented 9 years ago

Is it cool w/you if we close this and track progress in #442?

guybedford commented 9 years ago

Sure, thanks for your help!