NodeJS异步功能不起作用

时间:2018-05-02 07:02:37

标签: javascript node.js asynchronous

我想让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);
      }
    }

0 个答案:

没有答案