From b6d7de633e374998ea92352d5ce6a28d662fd9fa Mon Sep 17 00:00:00 2001 From: unknown <1149536116@qq.com> Date: Thu, 22 Sep 2016 13:46:54 +0800 Subject: [PATCH 1/4] custom Promise that you like . such as bluebird, q, when and so on. --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index aacf6ef..53368b4 100644 --- a/index.js +++ b/index.js @@ -5,12 +5,26 @@ var slice = Array.prototype.slice; +/** + * default Promise + */ + +var Promise = global.Promise; + /** * Expose `co`. */ module.exports = co['default'] = co.co = co; +/** + * custom your Promise that you like + */ + +co.setPromise = function (promise) { + Promise = promise; +} + /** * Wrap the given generator `fn` into a * function that returns a promise. From c4ad3fd084f1913063626af5c05ceff3f83ec153 Mon Sep 17 00:00:00 2001 From: unknown <1149536116@qq.com> Date: Thu, 22 Sep 2016 13:55:04 +0800 Subject: [PATCH 2/4] update readme.md --- Readme.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Readme.md b/Readme.md index 8ea2bb9..235efb6 100644 --- a/Readme.md +++ b/Readme.md @@ -196,6 +196,17 @@ fn(true).then(function (val) { }); ``` +### co.setPromise(Promise) + +You can custom `Promise` that you like . Such as `bluebird`, `q`, `when` and so on. + +```js +var Promise = require('bluebird'); +co.setPromise(Promise); + +co(11).tap(console.log); +``` + ## License MIT From 113493bd3ac80e4ecee1edce3434d21b538e171d Mon Sep 17 00:00:00 2001 From: liangwensen <1149536116@qq.com> Date: Tue, 21 Feb 2017 15:51:44 +0800 Subject: [PATCH 3/4] update the method witch defines the promise object --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 53368b4..8ab19d0 100644 --- a/index.js +++ b/index.js @@ -21,9 +21,14 @@ module.exports = co['default'] = co.co = co; * custom your Promise that you like */ -co.setPromise = function (promise) { - Promise = promise; -} +Object.defineProperty(co,"promise",{ + get: function () { + return Promise; + }, + set: function (promise) { + Promise = promise; + } +}); /** * Wrap the given generator `fn` into a From 64038a195d102db8206aadad33de4fec02b225de Mon Sep 17 00:00:00 2001 From: liangwensen <1149536116@qq.com> Date: Tue, 21 Feb 2017 15:53:51 +0800 Subject: [PATCH 4/4] update readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 235efb6..27730c7 100644 --- a/Readme.md +++ b/Readme.md @@ -202,7 +202,7 @@ You can custom `Promise` that you like . Such as `bluebird`, `q`, `when` and so ```js var Promise = require('bluebird'); -co.setPromise(Promise); +co.promise = Promise; co(11).tap(console.log); ```