Using await makes chaining Promises almost as simple as using sync-style coding on the server. In principle I would take something like that callWithPromise and just use multiple calls:
const thing = await callWithPromise('methodA'), {} );
const factor = await callWithPromise('methodB', { item: thing } );
const result = await callWithPromise('methodC', { item: thing, factor } );
The only “gotchas” you need to be aware of are:
- You can only
awaitinside anasyncfunction. However, you can do funky things likeTemplate.bob.onCreated(async function() {...which makes your entireonCreatedasync. - There is still likely to be a resolution step if you want to get a result from an
awaitchain out of yourasyncfunction and back into your “normal” code. In Meteor you can do this easily by making use ofReactiveVars.
So, in Blaze, you could do something like:
Template.bob.onCreated(async function() {
this.result = new ReactiveVar();
const thing = await callWithPromise('methodA'), {} );
const factor = await callWithPromise('methodB', { item: thing } );
this.result.set(await callWithPromise('methodC', { item: thing, factor } ));
}
Template.bob.helpers({
getResult() {
return Template.instance().result.get();
}
});