From bb740c5cc2457176b1ff5a9708315f150691e362 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Wed, 19 Feb 2014 14:12:54 -0800 Subject: [PATCH] Add constantly alias for repeated async loops --- dist/utils.js | 4 ++++ src/utils.coffee | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/dist/utils.js b/dist/utils.js index cbbc729..7f06863 100644 --- a/dist/utils.js +++ b/dist/utils.js @@ -18,6 +18,10 @@ return setTimeout(action, delay); }; + global.constantly = function(action) { + return every(0, action); + }; + global.sleep = function(ms) { var i, start, _results; start = Date.now(); diff --git a/src/utils.coffee b/src/utils.coffee index 99f2727..f7e2981 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -34,6 +34,15 @@ global.every = (interval, action) -> global.after = (delay, action) -> setTimeout action, delay +# Public: Alias to the `every` function, but passing 0 +# Examples +# +# constantly -> console.log("hello world (and again and again)!") +# +# Returns an interval +global.constantly = (action) -> + every 0, action + # Public: Sleep - do nothing for some duration of time. # # ms - number of ms to sleep for