TypeScript
async/await vs. Promise.then()

by Benny Neugebauer

getBalances(): Promise<Balance[]> {
  const balances: Balance[] = [];

  return this.getAccounts().then((accounts: coinbase.Account[]) => {
    for (const account of accounts) {
      balances.push(new Balance(account.balance.currency, account.balance.amount));
    }

    return balances;
  });
}

async getBalances(): Promise<Balance[]> {
  const balances: Balance[] = [];

  const accounts: coinbase.Account[] = await this.getAccounts();
  for (const account of accounts) {
    balances.push(new Balance(account.balance.currency, account.balance.amount));
  }

  return balances;
}