diff options
| author | Stephen Blott | 2015-05-10 06:45:37 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-10 06:45:37 +0100 | 
| commit | 198dd8fa89148f3389c289bf71c40b9ab1a5681f (patch) | |
| tree | 754824aa284c75b46c19db0a76d49fe0a23ff9e0 /lib/utils.coffee | |
| parent | 5fdbb8e579c068a54e9a397097d87063a3d8a146 (diff) | |
| download | vimium-198dd8fa89148f3389c289bf71c40b9ab1a5681f.tar.bz2 | |
Search completion; refactor job-running logic.
Diffstat (limited to 'lib/utils.coffee')
| -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 | 
