跳到主要内容
CNode

这个generator的坑怎么出?

问答
Bbgdsh发布于 10 年前最后回复 10 年前
439240
co(function* (){
  var token = yield sts.assumeRole('role', policy, 15 * 6, 'client-upload');
  console.log(token);
}).catch(function(err) {
  console.log(err.message);
});

这是阿里云OSS中关于STS的代码,官方文档表现正常。

sts.assumeRole('role', policy, 15 * 6, 'client-upload')
.next().value
.then(function(token) {
  console.log(token.data.toString());
})
.catch(function(err) {
  console.log(err);
});

我想既然Node v6.9.1 已经原生支持了generator,所以试着这样写,发现错误消息是从then抛出的。 请问大神怎样在不用co模块的情况下使用这个SDK。

查看回复

回复 (4)

B
bgdsh#410 年前

统一回复一下三位大哥,sdk里面有封装过的方法了。文档写的不清楚,看了源码找到了promise方法。

L
leizongmin#310 年前

这个 runner 还可以是它 https://github.com/leizongmin/lei-coroutine

M
magicdawn#210 年前

generator 需要不断的 next 的, 不用 co, 你需要造一个 co 去帮你不断 next, 直到 done = true 这个 runner 还可以是 bluebird.coroutine

I
immatt2015#110 年前

没看懂为啥要这样写 自豪地采用 CNodeJS ionic

参与回复

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