I am trying to set a timer and then return a value when the timer reaches a certain limit. In the code below I need to return the value once the timeElapsed reaches 3.
var timeElapsed = 0;
var interval;
var ExportApi = {
tick: function() {
timeElapsed ++;
if (timeElapsed == 3) {
clearInterval(interval);
}
console.log(timeElapsed);
},
getValues: function() {
interval = setInterval(this.tick, 1000);
//Once interval completes return the following values:
return [{val: '1'}, {val: '2'}];
}
};
module.exports = ExportApi;
//Call get Values
var x = ExportApi.getValues();