我想让async函数与.map循环并行工作。
当我在下面打电话时,我得到'承诺',例如
console.log(getExchangeRate(variable));
嘿我试图在NodeJS中运行Async函数,在其中并行进行一些计算。
const getExchangeRate = async (orderBaseCurrency) => {
try {
const exchangeRate = await axios.get(`http://api.example.com`);
const data = exchangeRate.data.data.rates;
const usd = data.usd;
const aud = data.aud;
// loop through above with the calc below in parallel
const decimalEntry = new Decimal(1);
const answer = new Decimal(decimalEntry.times(orderAmount).toFixed(18, Decimal.ROUND_HALF_UP));
return answer.toPrecision();
//^^ loop
} catch (error) {
console.error(error);
console.log(error);
}
}