Class: Immutable::Splitter::Left

Inherits:
Realizable show all
Defined in:
lib/immutable/list.rb

Constant Summary

Constants included from List

List::CADR

Instance Method Summary collapse

Methods inherited from Realizable

#cached_size?, #empty?, #head, #realized?, #size, #tail

Methods included from List

#<<, [], #add, #append, #at, #break, #cached_size?, #chunk, #clear, #combination, #cycle, #delete, #delete_at, #drop, #drop_while, #dup, #each, #each_chunk, empty, #eql?, #fill, #flat_map, #flatten, from_enum, #group_by, #hash, #indices, #init, #inits, #insert, #inspect, #intersperse, #last, #map, #merge, #merge_by, #partition, #permutation, #pop, #pretty_print, #respond_to?, #reverse, #rotate, #sample, #select, #size, #slice, #sort, #sort_by, #span, #split_at, #subsequences, #tails, #take, #take_while, #to_list, #transpose, #union, #uniq, #zip

Methods included from Enumerable

#<=>, #==, #compact, #each_index, #grep, #grep_v, #group_by, #inspect, #join, #partition, #pretty_print, #product, #reject, #sort_by, #sum, #to_set

Methods included from Enumerable

#to_list

Constructor Details

#initialize(splitter, buffer, mutex) ⇒ Left

Returns a new instance of Left.



1509
1510
1511
1512
# File 'lib/immutable/list.rb', line 1509

def initialize(splitter, buffer, mutex)
  super()
  @splitter, @buffer, @mutex = splitter, buffer, mutex
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Immutable::List

Instance Method Details

#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
    loop do
      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