diff --git a/Readme.md b/Readme.md index 8ea2bb9..27730c7 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.promise = Promise; + +co(11).tap(console.log); +``` + ## License MIT diff --git a/index.js b/index.js index aacf6ef..8ab19d0 100644 --- a/index.js +++ b/index.js @@ -5,12 +5,31 @@ 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 + */ + +Object.defineProperty(co,"promise",{ + get: function () { + return Promise; + }, + set: function (promise) { + Promise = promise; + } +}); + /** * Wrap the given generator `fn` into a * function that returns a promise.