diff options
| author | Stephen Blott | 2015-05-10 05:35:50 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-10 05:39:15 +0100 | 
| commit | 313a1f96d666f23c2bc75ef340f0f828319e127c (patch) | |
| tree | 8061232ac2d1affd10627f220381572dd6a1b001 /lib | |
| parent | 275a91f203086b8f81542c174e736748dce68628 (diff) | |
| download | vimium-313a1f96d666f23c2bc75ef340f0f828319e127c.tar.bz2 | |
Search completion; refactor searchEngineCompleter.
This revamps how search-engine configuration is handled, and revises
some rather strange legacy code.
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 4c2a7a14..51b16351 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -260,6 +260,22 @@ class SimpleCache        delete @previous[key]      value +# This is a simple class for the common case where we want to use some data value which may be immediately +# available, or we may have to wait.  It implements the use-immediately-or-wait queue, and calls the function +# to fetch the data asynchronously. +class AsyncDataFetcher +  constructor: (fetch) -> +    @data = null +    @queue = [] +    fetch (@data) => +      Utils.nextTick => +        callback @data for callback in @queue +        @queue = null + +  use: (callback) -> +    if @data? then callback @data else @queue.push callback +  root = exports ? window  root.Utils = Utils  root.SimpleCache = SimpleCache +root.AsyncDataFetcher = AsyncDataFetcher | 
