Permalink
Browse files

Made it so evoked callback only gets called once, after all evocation…

…s have begun.
  • Loading branch information...
1 parent 8ae071c commit 152a1375bc7963ae00348dd70c827499b5e7a276 Samuel Tesla committed May 26, 2009
Showing with 19 additions and 7 deletions.
  1. +19 −7 lib/pelvis/outcall.rb
View
@@ -61,18 +61,19 @@ def evoke_to(identities)
def evoke(identity)
e = Evocation.start(self, identity)
- evocations[e] = false
+ evocations[e] = :created
e.on_begun do
logger.debug "outcall begun: #{identity}"
- evoked
+ evocations[e] = :begun
+ check_begun
end
e.on_received do |data|
logger.debug "outcall received: #{identity}: #{data.inspect}"
received(data)
end
e.on_completed do |event|
logger.debug "outcall completed: #{identity}: #{event.inspect}"
- evocations[e] = true
+ evocations[e] = :finished
check_complete
end
e.on_failed do |error|
@@ -83,7 +84,7 @@ def evoke(identity)
logger.debug "Waiting #{time} seconds before retrying"
EM.add_timer(time) { @retried_times += 1; evoke(identity) }
else
- evocations[e] = true
+ evocations[e] = :finished
finish
failed(error)
end
@@ -102,10 +103,19 @@ def max_retries
5
end
+ def check_begun
+ return unless @all_sent
+ return if finished?
+ if evocations.values.none? {|s| s == :created}
+ logger.debug "All evocations are begun"
+ evoked
+ end
+ end
+
def check_complete
return unless @all_sent
return if finished?
- if evocations.values.all?
+ if evocations.values.all? {|s| s == :finished}
logger.debug "All evocations are finished"
finish
completed "Done at #{Time.now}"
@@ -126,8 +136,10 @@ def evocations
def put(data)
logger.debug "outcall put: #{data.inspect}"
- evocations.each do |e, finished|
- e.put(data) unless finished
+ evocations.each do |e, state|
+ # TODO: Probably should create a timer if the state is :started
+ # TODO: Probably should error somehow if the state is :finished
+ e.put(data) if state == :begun
end
end

0 comments on commit 152a137

Please sign in to comment.