ali-sdk / node-dingtalk

node sdk for dingtalk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

可否增加支持 async await

JokerLZD opened this issue · comments

  • Node Version:8.2.1
  • Platform: macOS 10.12.6

一开始用 async 和 await 去调用,结果没有任何返回值,后来看了源码 就用了 yield 了 结果就好使了,可以增加对 async 和 await 的支持吗?

async getDingDep() {
      const data = await this.app.dingtalk.department.list();
      console.log(data);
}

这样 是获取不到部门的

 *  getDingDep() {
      const data = yield this.app.dingtalk.department.list();
      console.log(data);
}

这样就是可以的

commented

await 后面应该是一个 Promise
dingtalk.department.list 是 Generator, 可以用 co 转一下

  • code
'use strict';

const co = require('co');
const DingTalk = require('node-dingtalk');

const dingtalk = new DingTalk({
  corpid: '',
  corpsecret: '',
});

async function listDepartment() {
  const department = await co(dingtalk.department.list());
  console.log(department);
}

listDepartment();

喔,昨天看错地方了,以为是 egg 的 issue。

@thonatos 谢谢了 看来还是我的问题

@atian25 我的我的 哈哈

因为 8 还没有 LTS,所以暂时不会升级到 async,自己 wrap 就好了。