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[++symbolCtr % (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 :)
@PaddeK started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Maybe it is a timing issue and using a Promise could help.. dont know the complete code but something like this could work:
And in your other code just do:
Error handling ommited for keeping it simple.. but you should take care of it :)