소스 검색

- fixes for interval menager

Ksawery Kuklinski 8 년 전
부모
커밋
e49c0e1d56
1개의 변경된 파일9개의 추가작업 그리고 4개의 파일을 삭제
  1. 9 4
      intervalMenager.js

+ 9 - 4
intervalMenager.js

@@ -24,15 +24,20 @@ module.exports = class intervalMenager {
     return this;
   }
   getLast(){
-    return new Date() - this.lastInterval();
+    if (this.lastInterval === null) {
+      return 0;
+    }
+    return (new Date()) - this.lastInterval;
   }
   start(){
     if (this.intervalId === null) {
-      var self = this;
-      this.intervalId = setInterval(function () {
+      var fun = function () {
         self.function(++self.id);
         self.lastInterval = new Date();
-      }, this.interval);
+      };
+      var self = this;
+      this.intervalId = setInterval(fun, this.interval);
+      setTimeout(fun, 1);
       return this;
     }else{
       throw new Error("Interval already started");