Skip to content

Commit

Permalink
perf(integrations): retrieve balances in parallel, via Promise.all() (#…
Browse files Browse the repository at this point in the history
…15)

* Use Promise.all() for integrations
* Reset portfolio on start
  • Loading branch information
barryvdh authored and benmarten committed Dec 30, 2017
1 parent b7db3d5 commit 0e3d6c0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const settings = require('../settings.json')
async function refreshPortfolio() {
return new Promise(async (resolve) => {
try {
Portfolio.clear()
await Coinmarket.init()
let integrations = {}
let promises = [];

for (let account in settings.accounts) {
let name = Utils.capitalize(account)
Expand All @@ -23,14 +25,15 @@ async function refreshPortfolio() {
try {
if (settings.accounts[account] && settings.accounts[account].length > 0) {
console.log(`Retrieving ${name} balance...`)
let coins = await integrations[name].default.getBalance()
await Portfolio.addCoins(coins)
promises.push(integrations[name].default.getBalance().then(coins => Portfolio.addCoins(coins)))
}
} catch (e) {
console.log(`Error: An error occured while running integration: ${name}, ${e}`)
}
}

await Promise.all(promises);

for (let index in settings.otherHoldings) {
if (settings.otherHoldings.hasOwnProperty(index)) {
let otherHolding = settings.otherHoldings[index]
Expand Down

0 comments on commit 0e3d6c0

Please sign in to comment.