You are reading a single comment by @PaddeK and its replies. Click here to read the full conversation.
  • Maybe it is a timing issue and using a Promise could help.. dont know the complete code but something like this could work:

    function getPrices() {
      return new Promise((resolve, reject) => {
        h.get(`${proxy}${api}${symbols[++symbolC­tr % (symbols.length + 1)]}-${currency}`, res => {
          let pricesRaw = "";
          res.on('data', d => pricesRaw += d);
          res.on('close', () => (prices[symbol] = JSON.parse(pricesRaw), true) && resolve());
        });
      });
    }
    

    And in your other code just do:

    getPrices().then(showPrices);
    

    Error handling ommited for keeping it simple.. but you should take care of it :)

About

Avatar for PaddeK @PaddeK started