Class: Archipelago::Current::Queue
- Inherits:
-
Object
- Object
- Archipelago::Current::Queue
- Defined in:
- lib/archipelago/current.rb
Instance Method Summary collapse
- #<<(e) ⇒ Object
- #empty?(wait = false) ⇒ Boolean
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #shift ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
37 38 39 40 41 |
# File 'lib/archipelago/current.rb', line 37 def initialize @lock = Monitor.new @flag = MonitorMixin::ConditionVariable.new(@lock) @ary = [] end |
Instance Method Details
#<<(e) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/archipelago/current.rb', line 42 def <<(e) @lock.synchronize do @ary << e @flag.broadcast end end |
#empty?(wait = false) ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/archipelago/current.rb', line 48 def empty?(wait = false) @lock.synchronize do if wait @flag.wait_until do @ary.empty? end unless @ary.empty? return @ary.empty? else return @ary.empty? end end end |
#shift ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/archipelago/current.rb', line 60 def shift @lock.synchronize do @flag.wait_while do @ary.empty? end if @ary.empty? @flag.broadcast return @ary.shift end end |