Method: Immutable::Splitter::Left#realize

Defined in:
lib/immutable/list.rb

#realizeObject



1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
# File 'lib/immutable/list.rb', line 1514

def realize
  # another thread may get ahead of us and null out @mutex
  mutex = @mutex
  mutex && mutex.synchronize do
    return if @head != Undefined # another thread got ahead of us
    while true
      if !@buffer.empty?
        @head = @buffer.shift
        @tail = Left.new(@splitter, @buffer, @mutex)
        @splitter, @buffer, @mutex = nil, nil, nil
        return
      elsif @splitter.done?
        @head, @size, @tail = nil, 0, self
        @splitter, @buffer, @mutex = nil, nil, nil
        return
      else
        @splitter.next_item
      end
    end
  end
end