co icon indicating copy to clipboard operation
co copied to clipboard

choose Promise which you like

Open vincentgor opened this issue 9 years ago • 6 comments

if we don't like to use native Promise, we can choose other Promises, such as bluebird.

co.set(require('bluebird'));
co(1).tap(console.log);

by using it ,we can use the tap function of Promise


update on 2017/2/21

co.promise = require('bluebird');
co(1).tap(console.log);

vincentgor avatar Sep 22 '16 06:09 vincentgor

Are the any solid reasons of using generators along with non-native Promises?

jakwuh avatar Sep 29 '16 21:09 jakwuh

Personnaly I would like to have this option. And about the why :

  • performance (native promise are slow)
  • avoid the pattern bluebird.resolve(co.wrap(...)) if you need some helper from bluebird for example

And I can't see any reason why not ?

jeanbaptiste-brasselet avatar Oct 14 '16 10:10 jeanbaptiste-brasselet

@jeanbaptiste-brasselet-planorama yes, this absolutely makes sense.

jakwuh avatar Oct 14 '16 12:10 jakwuh

@jeanbaptiste-brasselet-planorama I agree with you. But I just consider the second point. As I said above, if I want to use some functions with bluebird, such as co(1).tap(console.log);, I hava to use bluebird.resolve(co.(...)). It is a fact that your ability to express a lot better than I do.

vincentgor avatar Oct 16 '16 02:10 vincentgor

yeah it should be

axetroy avatar Dec 01 '16 03:12 axetroy

Of course this is a valuable feature! +1

deepal avatar Jun 20 '17 05:06 deepal