Class: QueueWithTimeout

Inherits:
Queue
  • Object
show all
Defined in:
lib/queue-with-timeout.rb

Overview

Ждём сообщения в очередь, при наступлении таймаута (если указан) вкидываем nil.

Instance Method Summary collapse

Instance Method Details

#pop(tmout = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/queue-with-timeout.rb', line 6

def pop( tmout = nil )
  if tmout.present? && tmout > 0
    that      = self
    dog       = Thread.new {
      sleep tmout
      that << nil
    }
  end
  ret = super()
  dog.kill.join
  return ret
end