Sunday, 16 April 2017

Meteor.setTimeout return after the timeout

I have this switch case,

var res=null;
switch(case){
case "Delay":
        console.log("Start Delay");
        var timer = Meteor.setTimeout(function(){
            console.log("done Delay");
            res="sample";
        },15000);
        console.log("test Delay");
        break;
}
return res;

The code above will log "Start Delay" & "test Delay". Then it will start the timer. After 15000ms, it will log "done Delay". The problem here is the returning of res variable. Before the start of the timer, it already return res which is a null.

How can I return a variable after the timeout?



via JMA

No comments:

Post a Comment