[Groonga-commit] droonga/droonga-engine at e8e0e23 [master] Make Deferrable module to accept multiple "on_ready" callbacks

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Apr 21 11:02:52 JST 2015


YUKI Hiroshi	2015-04-21 11:02:52 +0900 (Tue, 21 Apr 2015)

  New Revision: e8e0e23ecf1a5336baf2a4bfaac2a79de8e41929
  https://github.com/droonga/droonga-engine/commit/e8e0e23ecf1a5336baf2a4bfaac2a79de8e41929

  Message:
    Make Deferrable module to accept multiple "on_ready" callbacks

  Modified files:
    lib/droonga/deferrable.rb

  Modified: lib/droonga/deferrable.rb (+16 -2)
===================================================================
--- lib/droonga/deferrable.rb    2015-04-21 10:45:00 +0900 (2b0dee4)
+++ lib/droonga/deferrable.rb    2015-04-21 11:02:52 +0900 (1977c52)
@@ -15,7 +15,7 @@
 
 module Droonga
   module Deferrable
-    attr_writer :on_ready, :on_failure
+    attr_writer :on_failure
 
     def wait_until_ready(target)
       target.on_ready = lambda do
@@ -23,9 +23,23 @@ module Droonga
       end
     end
 
+    def on_ready=(callback)
+      @on_ready_callbacks ||= []
+      if callback
+        @on_ready_callbacks << callback
+      else
+        @on_ready_callbacks.clear
+      end
+      callback
+    end
+
     private
     def on_ready
-      @on_ready.call if @on_ready
+      if @on_ready_callbacks
+        @on_ready_callbacks.each do |callback|
+          callback.call
+        end
+      end
     end
 
     def on_failure
-------------- next part --------------
HTML����������������������������...
Descargar 



More information about the Groonga-commit mailing list
Back to archive index