Merge pull request #1896 from strongloop/feature/upgrade-to-bluebird

[SEMVER-MAJOR] Always use bluebird as promise library
This commit is contained in:
Janny 2016-01-09 03:31:32 +08:00
commit 70984bd5c0
4 changed files with 17 additions and 21 deletions

View File

@ -19,3 +19,17 @@ https://github.com/strongloop/loopback/issues/275
When upgrading application from previous loopback versions, simply remove When upgrading application from previous loopback versions, simply remove
loopback-datasource-juggler from your dependencies. loopback-datasource-juggler from your dependencies.
## always use bluebird as promise library
In version 3.0, we always use bluebird as our promise library
instead of `global.Promise`.
We consider Bluebird API a part of LoopBack API from now on,
you are welcome to use any Bluebird-specific methods in your applications.
If you are using LoopBack with a custom promise implementation provided
via `global.Promise`,
you will have to check all places where you are using non-standard promise API
and update them to use Bluebird API instead.
Please see [Related code change](https://github.com/strongloop/loopback/pull/1896) here.

View File

@ -1,17 +1,9 @@
exports.createPromiseCallback = createPromiseCallback; exports.createPromiseCallback = createPromiseCallback;
var Promise = require('bluebird');
function createPromiseCallback() { function createPromiseCallback() {
var cb; var cb;
var promise = new Promise(function(resolve, reject) {
if (!global.Promise) {
cb = function() {};
cb.promise = {};
Object.defineProperty(cb.promise, 'then', { get: throwPromiseNotDefined });
Object.defineProperty(cb.promise, 'catch', { get: throwPromiseNotDefined });
return cb;
}
var promise = new global.Promise(function(resolve, reject) {
cb = function(err, data) { cb = function(err, data) {
if (err) return reject(err); if (err) return reject(err);
return resolve(data); return resolve(data);
@ -20,9 +12,3 @@ function createPromiseCallback() {
cb.promise = promise; cb.promise = promise;
return cb; return cb;
} }
function throwPromiseNotDefined() {
throw new Error(
'Your Node runtime does support ES6 Promises. ' +
'Set "global.Promise" to your preferred implementation of promises.');
}

View File

@ -37,6 +37,7 @@
"dependencies": { "dependencies": {
"async": "^0.9.0", "async": "^0.9.0",
"bcryptjs": "^2.1.0", "bcryptjs": "^2.1.0",
"bluebird": "^3.1.1",
"body-parser": "^1.12.0", "body-parser": "^1.12.0",
"canonical-json": "0.0.4", "canonical-json": "0.0.4",
"continuation-local-storage": "^3.1.3", "continuation-local-storage": "^3.1.3",
@ -59,7 +60,6 @@
"underscore.string": "^3.0.3" "underscore.string": "^3.0.3"
}, },
"devDependencies": { "devDependencies": {
"bluebird": "^2.9.9",
"browserify": "^10.0.0", "browserify": "^10.0.0",
"chai": "^2.1.1", "chai": "^2.1.1",
"es5-shim": "^4.1.0", "es5-shim": "^4.1.0",

View File

@ -47,7 +47,3 @@ assert.isFunc = function(obj, name) {
assert(obj, 'cannot assert function ' + name + ' on object that doesnt exist'); assert(obj, 'cannot assert function ' + name + ' on object that doesnt exist');
assert(typeof obj[name] === 'function', name + ' is not a function'); assert(typeof obj[name] === 'function', name + ' is not a function');
}; };
if (!('Promise' in global)) {
global.Promise = require('bluebird');
}