Method: Qwirk::Adapter::InMemory::Queue#write

Defined in:
lib/qwirk/adapter/in_memory/queue.rb

#write(obj) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/qwirk/adapter/in_memory/queue.rb', line 61

def write(obj)
  @array_mutex.synchronize do
    # We just drop the message if no workers have been configured yet
    while !@stopping
      if @max_size == 0
        Qwirk.logger.warn "No worker for queue #{@name}, dropping message #{obj.inspect}"
        return
      end
      if @max_size < 0 || @array.size < @max_size
        @array << obj
        @read_condition.signal
        return
      end
      # TODO: Let's allow various write_full_modes such as :block, :remove_oldest, ? (Currently only blocks)
      @write_condition.wait(@array_mutex)
    end
    Qwirk.logger.warn "Queue has been stopped #{@name}, dropping message #{obj.inspect}"
  end
end