How can i block program before getting callback res?

var bit;‘getbid’,code,function(err,res){
bit = res;
return bit;

I want to return the result of the callback function, but before the result back, the undefined bit will be returned. how to return the value after getting the callback result?

is this a one time call per template instance, or is it bound to change during the lifetime of the template?

if it’s just a single occurrence, I’d move the method call to the Template.quote.created event, and communicate the result to the helper using a reactive variable:

Template.quote.created = function() { 
          var instance = this;         
          instance.currentBid = new ReactiveVar;
         var code =; // assuming you get the code in the data context'getbid', code, function(err, res) {

  bid: function() { 
       return Template.instance().currentBid.get(); 

quite horrible, but that’s where Meteor falls short.

it works. but it should add reactive-var package first.

However, for my case, the ‘code’ is come from another‘getcode’,id,function(err,res){ //id is known variable
code = res;

so I wonder how let the method ‘getbid’ executing after getting the result from method ‘getcode’ ?

if your async calls are becoming more complex and involved, there are 2 things you may consider:

  1. using Promises to organize them. in this specific case, you would use a serial pattern, i.e. one promise acting upon the completion of a previous one

  2. if possible, perhaps there’s reason to refactor the 2 methods into 1

in either case, this issue does not necessarily concern Meteor as a platform, as Meteor has been relatively agnostic about this so far

you can try ReactiveMethod package.