Class: Kraps::TimeoutQueue

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/kraps/timeout_queue.rb

Instance Method Summary collapse

Constructor Details

#initializeTimeoutQueue

Returns a new instance of TimeoutQueue.



5
6
7
8
9
10
# File 'lib/kraps/timeout_queue.rb', line 5

def initialize
  super

  @cond = new_cond
  @queue = []
end

Instance Method Details

#deq(timeout:) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/kraps/timeout_queue.rb', line 19

def deq(timeout:)
  synchronize do
    @cond.wait(timeout) if @queue.empty?

    return @queue.empty? ? nil : @queue.shift
  end
end

#enq(item) ⇒ Object



12
13
14
15
16
17
# File 'lib/kraps/timeout_queue.rb', line 12

def enq(item)
  synchronize do
    @queue << item
    @cond.signal
  end
end