CNode

求指点,express-promise是如何实现无回调读取数据库的(附代码)

IimWildCat发布于12 年前最后回复12 年前2 回复4650 浏览0 收藏

https://github.com/luin/express-promise

最近在看promise,不是很理解下面是如何实现的(github源码没看懂),promise最后的调用肯定会有.done()或者.then()里面带有回调啊。

app.get('/users/:userId', function(req, res) {
    res.json({
        user: User.find(req.params.userId),
        memo: Project.getMemo(req.params.userId)
    });
});
查看回复

回复 (2)

F
fundon#1·12 年前

不错的中间件,小巧 看了源码,覆盖重写了res.send(), res.json(), res.render() https://github.com/luin/express-promise/blob/master/lib/express_promise.js#L9 resolveAsync() 处理完再交给 原始的 res.send(), res.json(), res.render() response.

参与回复
登录后即可参与回复。登录