<分区>
我在函数内部有一个 promise 链,我想 console.log
从链内部的 2 个函数返回的值。我该怎么做?使用我当前的代码,我从 si.cpuTemperature()
获取值,然后从 undefined
获取值,但我想从 si.cpu()
获取值> 然后是 si.cpuTemperature()
。
const si = require('systeminformation');
function getCPUInfo() {
return new Promise((resolve) => {
resolve();
console.log("Gathering CPU information...");
return si.cpu()
// .then(data => cpuInfo = data) - no need for this, the promise will resolve with "data"
.catch(err => console.log(err)); // note, doing this will mean on error, this function will return a RESOLVED (not rejected) value of `undefined`
})
.then(() => {
return si.cpuTemperature().catch(err => console.log(err));
});
}
getCPUInfo().then((data1, data2) => console.log(data1, data2));