diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/utils.coffee | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee index b0abfd8f..16adc305 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -278,7 +278,23 @@ class AsyncDataFetcher use: (callback) -> if @data? then callback @data else @queue.push callback +# This takes a list of jobs (functions) and runs them, asynchronously. Functions queued with @onReady() are +# run once all of the jobs have completed. +class JobRunner + constructor: (@jobs) -> + @fetcher = new AsyncDataFetcher (callback) => + for job in @jobs + do (job) => + Utils.nextTick => + job => + @jobs = @jobs.filter (j) -> j != job + callback true if @jobs.length == 0 + + onReady: (callback) -> + @fetcher.use callback + root = exports ? window root.Utils = Utils root.SimpleCache = SimpleCache root.AsyncDataFetcher = AsyncDataFetcher +root.JobRunner = JobRunner |
