首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >nodejs -- promise的返回

nodejs -- promise的返回

作者头像
战神伽罗
发布于 2019-07-24 08:45:56
发布于 2019-07-24 08:45:56
2.1K0
举报

[javascript] view plain copy

  1. const a = async () => {
  2. return Sequelize.findAll({}) //这里返回一个promise,"aaaaa"也行
  3. }
  4. const b= async ()=>{
  5. const result =await a() ; //这样就能拿到数据了
  6. }

OR

[javascript] view plain copy

  1. const a = async () => {
  2. return new Promise((resolve,reject)=>{
  3. resolve(data)
  4. })
  5. }
  6. a().then((data)=>{
  7. console.log(data) //拿到了数据
  8. })

OR

[javascript] view plain copy

  1. const a= async ()=> {
  2. return "aaaaaa"
  3. }
  4. a().then((result)=>{
  5. console.log(result)
  6. })

OR

[javascript] view plain copy

  1. const a = async () => {
  2. return Sequelize.findAll({}) //这里返回一个promise
  3. }
  4. a().then(result=>{
  5. console.log(result) //拿到了数据
  6. })
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档