文章详情页
node.js - 函数getByName()中如何使得co执行完后才return
浏览:431日期:2024-07-16 14:14:46
问题描述
express中判断用户登录(使用了sequelize和co)但是是return res之后才看到console.log中的信息。如何使得执行完co中的函数才return?
问题解答
回答1:一般是返回个Promise,使用的地方也要then一下。
UserBLL.GetByName = function(name) { return co(function() {return yield User.findOne({where: {username: name}}) })}UserBLL.GetByName(’xxx’).then(function(res) { console.log(res)})回答2:
UserBil.getByName = () => { var result = co.wrap(function* (){return request// something you want to return })return result(true).then(function(value){ return value })}
上一条:在介绍Node.js的相关资料中,$ npm install express中的$代表什么?下一条:node.js 安装报错 node-v可以看到版本号,但是npm -v 会报错,在线等,求解
相关文章:
1. html - 竖线怎么实现2. python - 用ffmpeg采集视频,用terminate没法结束进程3. python - pandas读取中文的时候乱码 要如何解决?4. clone - git sourceTree克隆仓库时,都不停弹出Password Required弹窗,即时输入正确的git账号密码还是弹出5. 超链接里的target问题6. python打包代码上传PYPI出现错误500,虚心求教7. PHP中的$this代表当前的类还是方法?8. navicat - Mysql无法连接9. thinkphp中Controller里面使用Request::File(’image’);10. python3.x - python多进程,不能在同一窗口吗
排行榜

网公网安备