Sha256: 6d415fa3d55df7eca87e3fa80b543ba724360a1e25b714c1a0e263a909b82f7c

Contents?: true

Size: 833 Bytes

Versions: 13

Compression:

Stored size: 833 Bytes

Contents

# -*- encoding: utf-8 -*-

# A simple synchronized message queue used to handle yielding MESSAGE frames
# to {OnStomp::OpenURI::ClientExtensions#each} blocks.
class OnStomp::OpenURI::MessageQueue
  def initialize
    @queue = []
    @queue.extend MonitorMixin
    @empty_check = @queue.new_cond
  end
  
  # Waits until the queue contains at least one element, then takes it out
  # and returns it.
  def shift
    take_from_queue :shift
  end
  
  # Puts a new object into the queue.
  def push msg
    put_in_queue :push, msg
  end
  alias :<< :push
  
  private
  def put_in_queue meth, msg
    @queue.synchronize do
      @queue.send meth, msg
      @empty_check.signal
    end
  end
  
  def take_from_queue meth
    @queue.synchronize do
      @empty_check.wait_while { @queue.empty? }
      @queue.send meth
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
onstomp-1.0.12 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.11 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.10 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.9 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.8 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.7 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.6 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.5 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.4 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.3 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.2 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.1 lib/onstomp/open-uri/message_queue.rb
onstomp-1.0.0 lib/onstomp/open-uri/message_queue.rb