Don't forget to lycansubscribe
1class ItemQueue
2 BATCH_SIZE = 25
3
4 def initialize(items = [])
5 @mutex = Mutex.new
6 @queue = items
7 end
8
9 def push(item)
10 @mutex.synchronize {
11 @queue << item
12 }
13 end
14
15 def pop_batch
16 @mutex.synchronize {
17 batch = @queue[0...BATCH_SIZE]
18 @queue = @queue[BATCH_SIZE..-1] || []
19 batch
20 }
21 end
22
23 def length
24 @mutex.synchronize {
25 @queue.length
26 }
27 end
28end