Class: Maze::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(enumerator) ⇒ Generator

Returns a new instance of Generator.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/maze/generator.rb', line 4

def initialize(enumerator)
  # A SizedQueue allows a set number of values to always be ready for clients
  # and will be automatically topped up from the enumerator.
  @queue = SizedQueue.new(10)

  # The queue filler continually adds to the queue (when there is room), taking
  # values from the Enumerator.  This ensure the enumerator is always run inside
  # the same thread
  @queue_filler = create_queue_filler(enumerator)

  while @queue.empty? && enumerator.size != 0
    # Wait for the queue to start filling
  end
end

Instance Method Details

#closeObject

Cleans up resources used by the generator



30
31
32
33
# File 'lib/maze/generator.rb', line 30

def close
  @queue_filler.exit
  @queue.close
end

#closed?Boolean

Returns Whether the generator has been closed.

Returns:

  • (Boolean)

    Whether the generator has been closed



25
26
27
# File 'lib/maze/generator.rb', line 25

def closed?
  @queue.closed?
end

#nextObject

Returns The next value.

Returns:

  • The next value



20
21
22
# File 'lib/maze/generator.rb', line 20

def next
  @queue.pop
end