0
> var index=0;
enyo.kind({
name:"Kapping",
events: {
    onBeat: ""
},
create : function(){
    this.inherited(arguments);
    this.timer = window.setInterval(enyo.bind(this,"beat"),1000);
},
destroy : function(){
    if(this.timer != undefined){
        window.clearInterval(this.timer);
    }
    this.inherited(arguments);
},
beat: function(){
    this.doBeat({
        //this.fetch();
    });
    index = index+1;
    console.log('Doing beat ' + index);
}

}); /*

new Kapping().renderInto(document.body);

In which beat function is getting called 2 times. and another one is

> var i =0;
enyo.kind({
name:"Heartbeat",
events: {
    onBeat: ""
},
create : function(){
    this.inherited(arguments);
    this.timer = window.setInterval(enyo.bind(this,"beat"),1000);
},
destroy : function(){
    if(this.timer != undefined){
        window.clearInterval(this.timer);
    }
    this.inherited(arguments);
},
beat: function(){
    this.doBeat({
    });
    i=i+1;
    console.log("In timer callback " + i);
}
});

new Heartbeat().renderInto(document.body);

In this beat function is getting called only once.

What am I missing?

arya
  • 81
  • 1
  • 8

1 Answers1

0

If you want it to run only once then you want setTimeout() not setInterval().

I'm not sure why you see different behavior but it is probably a timing issue as both samples run forever for me. Perhaps there is a problem elsewhere in your code.

Pre101
  • 2,370
  • 16
  • 23