Skip to content

Class Calls

Chaining Calls

Each backend call is a javascript promise, so they can be chained to happen one after another instead of simultaneously.

TheM.user.doLogin({
    userName:'demo',
    password:'demo'
}).then((json) =>{
    TheM.user.doUpdate()
});

In this case, the login call will resolve/reject first and then, if login is successful, the account update call will resolve.

The alternative async/await construction can be used as well:

await TheM.accounts.doUpdate(); 
await TheM.accounts[0].transactions.doUpdate();

Parallel Calls

When not chained, calls will happen concurrently.

TheM.user.doLogin({userName:'demo',password:'demo'});
TheM.accounts.doUpdate();

This will likely fail as the second call will happen before the first call has had a chance to resolve. Use parallel calls when you need to fetch unrelated data: accounts, beneficiaries, cards, fx-rates, etc.

await TheM.user.doLogin({userName:'demo',password:'demo'});
TheM.accounts.doUpdate();
TheM.cards.doUpdate();