lib/mongoid/lock/synch_methods.rb in mongoid-lock-0.0.3 vs lib/mongoid/lock/synch_methods.rb in mongoid-lock-0.0.4
- old
+ new
@@ -43,7 +43,21 @@
return true
rescue Mongoid::Lock::UnsynchronizedAccess => ua
return false
end
end
+
+ def wait_synchronized(timeout, &block)
+ started = Time.now
+ expires = started + timeout
+ begin
+ success = self.try_synchronized do
+ block.call()
+ end
+ unless (success)
+ sleep(2)
+ end
+ end while(not success and Time.now < expires)
+ return success
+ end
end
end
\ No newline at end of file