Co.js和bluebird.js —有什么区别? [英] Co.js and bluebird.js -- what's the difference?

查看:213
本文介绍了Co.js和bluebird.js —有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我理解在ES6 Harmony中使用Koa.js和Bluebird.js的区别.具体来说,

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

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

比较

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

似乎Koa应该使用Bluebird而不是重新创建轮子.有什么不同?

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

推荐答案

有一个拉出请求合作使用Bluebird.那里的评论应该使某些事情更清楚. co依赖于0.11中提供的本机V8 Promises功能,而Bluebird的目标是也可以在0.10中很好地工作.您可以在低于0.11的版本中使用co,但是Bluebird将是一个更好的选择.在该链接中,您可以看到基准测试表明co不比Bluebird慢,因此该说法不正确.

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.

此外,只有300行代码,坚持使用KISS通常是一个好习惯.因此,它不是在重新创建轮子.它正在减肥.您可以在几分钟内阅读代码并了解它的作用.我花了一个小时来阅读Bluebird API文档.还提到V8实现是已损坏,因此Bluebird可用于一个过渡期.

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.

这篇关于Co.js和bluebird.js —有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆