Class: Unipept::BatchOrder

Inherits:
Object show all
Defined in:
lib/batch_order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBatchOrder

Returns a new instance of BatchOrder.



5
6
7
8
# File 'lib/batch_order.rb', line 5

def initialize
  @order = {}
  @current = 0
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



3
4
5
# File 'lib/batch_order.rb', line 3

def order
  @order
end

Instance Method Details

#wait(i, &block) ⇒ Object

Executes block if it’s its turn, queues the block in the other case.



11
12
13
14
15
16
17
18
19
# File 'lib/batch_order.rb', line 11

def wait(i, &block)
  @order[i] = block
  return unless i == @current

  while order[@current]
    order.delete(@current).call
    @current += 1
  end
end