diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-29 17:26:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-29 21:43:05 -0700 |
commit | af0a9f9eefaee3a8120cfd8d05cbc431af376da3 (patch) | |
tree | 3eca858f42bf55c2e1d660434f3e782c524debab /activesupport/lib/active_support | |
parent | d4433a35215c5e32d5cb91885c4084f849988887 (diff) | |
download | rails-af0a9f9eefaee3a8120cfd8d05cbc431af376da3.tar.gz rails-af0a9f9eefaee3a8120cfd8d05cbc431af376da3.tar.bz2 rails-af0a9f9eefaee3a8120cfd8d05cbc431af376da3.zip |
added live responses which can be written and read in separate threads
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/concurrency/latch.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/concurrency/latch.rb b/activesupport/lib/active_support/concurrency/latch.rb new file mode 100644 index 0000000000..1507de433e --- /dev/null +++ b/activesupport/lib/active_support/concurrency/latch.rb @@ -0,0 +1,27 @@ +require 'thread' +require 'monitor' + +module ActiveSupport + module Concurrency + class Latch + def initialize(count = 1) + @count = count + @lock = Monitor.new + @cv = @lock.new_cond + end + + def release + @lock.synchronize do + @count -= 1 if @count > 0 + @cv.broadcast if @count.zero? + end + end + + def await + @lock.synchronize do + @cv.wait_while { @count > 0 } + end + end + end + end +end |