node开发,一个request中多次访问数据库再返回结果

来源:互联网 发布:mysql查询最小时间 编辑:程序博客网 时间:2024/05/16 17:22

在node开发的过程中,对于一次请求,需要多次查询数据库,得到需要的数据库后才能返回结果。

数据库的查询通常采取异步的方式完成,那么如何编写程序实现多次查询均结束后再返回页面呢?

一次是好做的,可以采用回调的方式。

多次就存在并发,需要考虑node的并行程序设计。


Node.js实战一书中,介绍的流程控制工具有Nimble、Step、Seq三个以及async(与Nimble是同一作者)。

这四个在npm中的最近下载量如下:

Nimble

8 downloads in the last day
205 downloads in the last week

1 654 downloads in the last month

Step

1 158 downloads in the last day
36 574 downloads in the last month

Seq

386 downloads in the last day
3 140 downloads in the last week
13 556 downloads in the last month

async

124 468 downloads in the last day
865 662 downloads in the last week
4 158 157 downloads in the last month

根据下载量可以看到流行程度

async>>Step>Seq>Nimble

0 0
原创粉丝点击