Skip to content

Conversation

@dead-horse
Copy link
Member

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc

Description of change

@mention-bot
Copy link

@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.

@dead-horse
Copy link
Member Author

eggjs/examples#12

@dead-horse dead-horse mentioned this pull request Feb 10, 2017
9 tasks
class PostController extends app.Controller {
* create() {
const ctx = this.ctx;
const { ctx, service } = this;
Copy link
Member

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 一样:
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

controller & service?

@dead-horse
Copy link
Member Author

fixed


- generator function

```js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个要缩进吧

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哪里缩进?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就是按 list 缩进

Copy link
Member Author

@dead-horse dead-horse Feb 11, 2017

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
  ``

这样?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恩,部分 markdown 需要4格,github 好像支持两格

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoding 没地方定义?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@codecov
Copy link

codecov bot commented Feb 11, 2017

Codecov Report

Merging #349 into master will not change coverage.

@@          Coverage Diff          @@
##           master   #349   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          28     28           
  Lines         636    636           
=====================================
  Hits          636    636

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae78092...2ef53cb. Read the comment docs.

@fengmk2 fengmk2 merged commit cd02057 into master Feb 11, 2017
@fengmk2 fengmk2 deleted the doc-async-await branch February 11, 2017 18:13
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 替代。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

编译出的文档,前面的章节 link 有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants