我试图从一系列承诺中获取价值。
async function retrieveIssues() {
let rawdata = fs.readFileSync(argv.i);
let issues = JSON.parse(rawdata);
const issuesArray = issues.Issues;
const promises = issuesArray.map(issue => getIssueInfo(issue));
await Promise.all(promises);
// promises is now array of current issue information
console.log(promises)
console.log(promises[0])
}
所以我拥有的是一系列Promise对象,如下所示:
Promise {
{ title: 'Work out why we can\'t run the GAX tests with parallelism',
body: 'We\'ve had to disable parallelism in GAX tests, as otherwise the FakeScheduler tests hang, although only on Travis... but it\'s not clear why. At some point, we should investigate that...\n',
labels: [ [Object] ] } }
那么,例如,我将如何获得标题?
最佳答案
当您想使用等待的promises
调用的结果时,仍在使用Promise.all
变量尝试访问值。例如:
const results = await Promise.all(promises);
// promises is now array of current issue information
console.log(results);
console.log(results[0]);
关于javascript - 从已解决的Promise对象中检索值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52283873/