Understanding Meteor.call nature (runs synchronous or asynchronous in server?) & best practice

Below is my code

//Client/somefile.js
Meteor.call("serverFunction" , params1 , params2,  (err,res)=>{
      if(err){
         console.log(err);
      }
      else{
         console.log(res);
      }
 });


//server/methods.js    -  Using promise
Meteor.methods({
  "serverFunction": function( params1, params2 ){
       return new Promise((resolve, reject)=>{
          Meteor.call( "functionOne" , params1 , (err1,res1)=>{
             if(err1){
                reject(err1);
              }
            if(someCondition)
               Meteor.call( "functionTwo" , params2 , (err2,res2)=>{
                 if(err2){
                   reject(err2);
                 }
               });
            }
             resolve(res1); // Q1 - Does this resolved before functionTwo completes?
         });
     });
  },
 "functionOne": function( params1 ){
     //Calls multiple methods inside promise
  },
 "functionTwo": function( params2 ){
     //Calls multiple methods inside promise
  },
});



//server/methods.js    -  Without promise
Meteor.methods({
  "serverFunction": function( params1, params2 ){
      try{
          var result = Meteor.call( "functionOne" , params1 );
          if(someCondition){
             Meteor.call( "functionTwo" , params2 ); // Q2 - Does this wait for functionOne to complete?
          }
          return result;
      }
      catch(err){
           throw err;
      }
  },
 "functionOne": function( params1 ){
     //Calls multiple methods inside promise
  },
 "functionTwo": function( params2 ){
     //Calls multiple methods inside promise
  },
});

I’m wondering about the best practice of calling several methods inside a meteor method (which is inside server folder). I have couple of doubts based on using callback and not using callback. Questions are inside the above code.

Note - I need to call the “functionTwo” only based on some condition. Therefore I couldn’t use resolve inside “functionOne” when using callback

A1: I dont understand your question. You can just put a few console.log statements in your code to see which fires first

A2: Meteor call without a callback is synchronous

So you can do

const response = Meteor.call('functionOne', params1)
Meteor.call('functionTwo', response)

Also, there is no need to make everything in your app inside a meteor.method. I tend to abstract to other functions that I export and then import & call it.

export const last = array => array[array.length - 1]