Class: Purplelight::WriterJSONL::PartSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/purplelight/writer_jsonl.rb

Overview

Allocates globally unique output part numbers across writer threads.

Instance Method Summary collapse

Constructor Details

#initialize(next_value = 0) ⇒ PartSequence

Returns a new instance of PartSequence.



29
30
31
32
# File 'lib/purplelight/writer_jsonl.rb', line 29

def initialize(next_value = 0)
  @next_value = next_value
  @mutex = Mutex.new
end

Instance Method Details

#nextObject



34
35
36
37
38
39
40
# File 'lib/purplelight/writer_jsonl.rb', line 34

def next
  @mutex.synchronize do
    value = @next_value
    @next_value += 1
    value
  end
end