From 313a1f96d666f23c2bc75ef340f0f828319e127c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 10 May 2015 05:35:50 +0100 Subject: Search completion; refactor searchEngineCompleter. This revamps how search-engine configuration is handled, and revises some rather strange legacy code. --- lib/utils.coffee | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3