Method: Traject::Util.drain_queue
- Defined in:
- lib/traject/util.rb
.drain_queue(queue) ⇒ Object
Ruby stdlib queue lacks a 'drain' function, we write one.
Removes everything currently in the ruby stdlib queue, and returns it an array. Should be concurrent-safe, but queue may still have some things in it after drain, if there are concurrent writers.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/traject/util.rb', line 116 def self.drain_queue(queue) result = [] queue_size = queue.size begin queue_size.times do result << queue.deq(:raise_if_empty) end rescue ThreadError # Need do nothing, queue was concurrently popped, no biggie, but let's # stop iterating and return what we've got. return result end return result end |