Co.js and bluebird.js -- what's the difference?
Asked Answered
C

2

6

Could someone help me understand the differences between using Koa.js and Bluebird.js with ES6 Harmony. Specifically, how does

co( function * () {
  //stuff
} );

compare to,

Promise.coroutine( function * () {
  //stuff
} );

It just seems Koa should be using Bluebird and not recreating the wheel. What's different?

Cakewalk answered 2/3, 2014 at 22:2 Comment(1)
When using Bluebird you should generally avoid Promise.spawn (now deprecated) in favor of Promise.coroutineEntreat
E
2

For now the difference is that Koa allows yielding more than just promises.

However a feature is being added that allows not only yielding callbacks, thunks etc but any arbitrary thing that comes to your mind. Bluebird is also the fastest. So after this version koa should be just using bluebird indeed.

See https://github.com/petkaantonov/bluebird/issues/131#issuecomment-36975495

Edee answered 7/3, 2014 at 8:10 Comment(1)
This is no longer correct. Bluebird now allows adding yield handlers.Entreat
I
2

There is a pull request on co to use Bluebird. The comments there should make certain things more clear. co relies on the native V8 Promises feature provided in 0.11 while Bluebird aims to work well in 0.10 too. You can use co in versions below 0.11 but then Bluebird would be a better option. In that link, you can see that the benchmarks show that co is not slower than Bluebird, so that argument is incorrect.

Plus, it is only 300 lines of code, sticking to KISS is generally a good practice. So it is not recreating the wheel. It is slimming it down. You can read the code and understand what it does in few minutes. It took me an hour to read through the Bluebird API doc. There is also a mention that the V8 implementation is broken, so Bluebird may be used for an interim period.

Impassive answered 17/7, 2014 at 12:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.