Permalink
Browse files

simplify logic in NodeDeletionWatcher timeout code

@eric and I are now even
  • Loading branch information...
1 parent 4a627a3 commit 4a314221abccf37c07f8f03b96a007df41d38bd5 @slyphon slyphon committed Aug 29, 2012
Showing with 10 additions and 9 deletions.
  1. +10 −9 lib/zk/node_deletion_watcher.rb
@@ -153,10 +153,10 @@ def wait_for_result(timeout)
if timeout # and here
now = Time.now
- if (now > time_to_stop)
- @result ||= TIMED_OUT # don't overwrite the @result
+ if @result
return
- elsif @result
+ elsif (now > time_to_stop)
+ @result = TIMED_OUT
return
end
@@ -181,12 +181,14 @@ def register_callbacks
def node_deletion_cb(event)
@mutex.synchronize do
+ return if @result
+
if event.node_deleted?
- @result ||= :deleted
+ @result = :deleted
@cond.broadcast
else
unless zk.exists?(path, :watch => true)
- @result ||= :deleted
+ @result = :deleted
@cond.broadcast
end
end
@@ -195,10 +197,9 @@ def node_deletion_cb(event)
def session_cb(event)
@mutex.synchronize do
- unless @result
- @result = event.state
- @cond.broadcast
- end
+ return if @result
+ @result = event.state
+ @cond.broadcast
end
end
end

0 comments on commit 4a31422

Please sign in to comment.