-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
docs: add async await #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@dead-horse, thanks for your PR! By analyzing the history of the files in this pull request, we identified @popomore and @atian25 to be potential reviewers. |
| class PostController extends app.Controller { | ||
| * create() { | ||
| const ctx = this.ctx; | ||
| const { ctx, service } = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对喔, 都忘记有这个了, 那回头可以改改 quickstart 和 hackernews
|
|
||
| ## 中间件 | ||
|
|
||
| egg 中所有的中间件,包括[标准定义方式](../basics/middleware.md)以及在[路由中定义的中间件](../basics/router.md#中间件的使用)都可以通过 async function 来编写。但是和 generator function 格式的中间件稍有不同的是,中间件的参数列表变化了,和 koa v2.x 一样: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
egg -> 框架
|
|
||
| **注意:在基于 async function 编写 egg 应用代码时,请确保你的代码运行在 node 7.6+ 的版本上。** | ||
|
|
||
| ## controller & controller |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controller & service?
|
fixed |
|
|
||
| - generator function | ||
|
|
||
| ```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个要缩进吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哪里缩进?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就是按 list 缩进
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- generator function
``js
// code
``
- async function
``js
// code
``这样?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恩,部分 markdown 需要4格,github 好像支持两格
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好像4个空格也会被视为 code 语法
|
|
||
| // 设置 gzip body,修正响应头 | ||
| ctx.body = zlib.createGzip().end(body); | ||
| ctx.set('Content-Encoding', encoding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encoding 没地方定义?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Codecov Report@@ Coverage Diff @@
## master #349 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 28 28
Lines 636 636
=====================================
Hits 636 636Continue to review full report at Codecov.
|
| title: 使用 async function 开发应用 | ||
| --- | ||
|
|
||
| [前面的章节](../intro/egg-and-koa.md#async function)中介绍了 [async function] 是 js 语言层面提供的异步解决方案,而 node 从 7.6.0 开始将会升级 v8 到 5.5,届时 async function 将不再需要开启 flag 即可使用。框架也默认支持了 async function,在所有支持 generator function 的地方都可以使用 async function 替代。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
编译出的文档,前面的章节 link 有问题
Checklist
Affected core subsystem(s)
doc
Description of change