Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor.setTimeout() issue in Meteor Timers?

I did a sample example on Meteor.setTimeout() using Meteor. In this example i get an error. I didn't have any idea about this.So please see the below code,error and suggest me how to do?

Error :

Exception in setTimeout callback: TypeError: undefined is not a function
    at _.extend.withValue (http://localhost:3000/packages/meteor.js?8ec262df25783897eaad01255bc8bd1ca4e78b24:773:17)
    at http://localhost:3000/packages/meteor.js?8ec262df25783897eaad01255bc8bd1ca4e78b24:358:45
    at http://localhost:3000/packages/meteor.js?8ec262df25783897eaad01255bc8bd1ca4e78b24:801:22 

JS Code :

   if (Meteor.isClient) 
{
  Meteor.setTimeout(Test("10"), 1000);
  Meteor.setInterval(Test1, 1000);

  Template.hello.greeting = function () 
  {
    return "Welcome to timerapp.";
  };

  Template.hello.events
  ({
    'click input' : function () 
    {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");

        //Test();
    }
  });
}
function Test(x)
{
   console.log("*** Test() ***"+x);
}
function Test1()
{
   console.log("*** Test1() ***");
}
if (Meteor.isServer)
 {

  Meteor.startup(function ()
  {
    // code to run on server at startup
  });


}
like image 886
user3213821 Avatar asked Jan 28 '14 10:01

user3213821


1 Answers

The problem is that setTimeout expects a function as a first parameter but you are passing the result of evaluating Test("10") which is "undefined".

You can solve the issue by wrapping your call to Test1 in an anonymous function:

Meteor.setTimeout(function(){Test("10");}, 1000);
like image 196
Tobias Avatar answered Nov 18 '22 08:11

Tobias