例如:
return getPackages()
.map(function(package){
console.log(package.name);
return latestAsync(package.name)
})
.each(function(version) {
//I want package to make it so it will be in this scope too
console.log(package.name, package.version, version)
});
我希望在履行承诺时将package
发送到下一个/然后
怎么可能?
我正在使用蓝鸟。
答案 0 :(得分:2)
您可以使用Promise.props
:
return getPackages()
.map(function(package){
console.log(package.name);
return Promise.props({version: latestAsync(package.name), package: package });
})
.each(function(r) {
//I want package to make it so it will be in this scope too
console.log(r.package.name, r.package.version, r.version)
});
替代解决方案是:
.bind
to set a scope explicitly并依赖索引。.then
上放置latestAsync
)。Promise.all
的对象。