Navigation Menu

Skip to content

Commit

Permalink
Make Deferrable module to accept multiple "on_ready" callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 21, 2015
1 parent 82a1000 commit e8e0e23
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/droonga/deferrable.rb
Expand Up @@ -15,17 +15,31 @@

module Droonga
module Deferrable
attr_writer :on_ready, :on_failure
attr_writer :on_failure

def wait_until_ready(target)
target.on_ready = lambda do
on_ready
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
Expand Down

0 comments on commit e8e0e23

Please sign in to comment.