Class: Smith::Tool::InvocationSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/tool/invocation_sequence.rb

Instance Method Summary collapse

Constructor Details

#initialize(next_ordinal: 1) ⇒ InvocationSequence

Returns a new instance of InvocationSequence.



6
7
8
9
10
11
12
13
# File 'lib/smith/tool/invocation_sequence.rb', line 6

def initialize(next_ordinal: 1)
  unless next_ordinal.is_a?(Integer) && next_ordinal.positive?
    raise ArgumentError, "next tool invocation ordinal must be positive"
  end

  @next_ordinal = next_ordinal
  @mutex = Mutex.new
end

Instance Method Details

#reserve(size) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
# File 'lib/smith/tool/invocation_sequence.rb', line 15

def reserve(size)
  raise ArgumentError, "tool invocation batch size must be positive" unless size.is_a?(Integer) && size.positive?

  @mutex.synchronize do
    first = @next_ordinal
    @next_ordinal += size
    first
  end
end