class Immutable::Partitioned

One of the `List`s which gets its items from a Partitioner @private

Public Class Methods

new(partitioner, buffer, mutex) click to toggle source
Calls superclass method Immutable::Realizable::new
# File lib/immutable/list.rb, line 1448
def initialize(partitioner, buffer, mutex)
  super()
  @partitioner, @buffer, @mutex = partitioner, buffer, mutex
end

Public Instance Methods

realize() click to toggle source
# File lib/immutable/list.rb, line 1453
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 = Partitioned.new(@partitioner, @buffer, @mutex)
        # don't hold onto references
        # tail will keep references alive until end of list is reached
        @partitioner, @buffer, @mutex = nil, nil, nil
        return
      elsif @partitioner.done?
        @head, @size, @tail = nil, 0, self
        @partitioner, @buffer, @mutex = nil, nil, nil # allow them to be GC'd
        return
      else
        @partitioner.next_item
      end
    end
  end
end