CNode

这个generator的坑怎么出?

问答
Bbgdsh发布于10 年前最后回复10 年前4 回复3900 浏览0 收藏
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)

I
immatt2015#1·10 年前

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

M
magicdawn#2·10 年前

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

L
leizongmin#3·10 年前

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

B
bgdsh#4·10 年前

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

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