Skip to content

Instantly share code, notes, and snippets.

@richardkundl
Created November 27, 2013 10:42
Show Gist options
  • Select an option

  • Save richardkundl/7673746 to your computer and use it in GitHub Desktop.

Select an option

Save richardkundl/7673746 to your computer and use it in GitHub Desktop.

Revisions

  1. richardkundl created this gist Nov 27, 2013.
    18 changes: 18 additions & 0 deletions setInterval.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    function interval(func, wait, times){
    var interv = function(w, t){
    return function(){
    if(typeof t === "undefined" || t-- > 0){
    setTimeout(interv, w);
    try{
    func.call(null);
    }
    catch(e){
    t = 0;
    throw e.toString();
    }
    }
    };
    }(wait, times);

    setTimeout(interv, wait);
    };
    3 changes: 3 additions & 0 deletions usage.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    interval(function(){
    // Code block goes here
    }, 1000, 10);