class FutureProof::FutureQueue

FutureQueue is designed to handle exceptions that happen in a threads. It raises an exception when user tries to access “exceptional” value.

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/future_proof/future_queue.rb, line 9
def initialize
  @finished = false
  super()
end

Public Instance Methods

[](index) click to toggle source

Returns FutureArray with all values.

@return [Object] value in a queue.

@note allowed only when queue is stopped. @note raises an exception if it happened during execution.

# File lib/future_proof/future_queue.rb, line 59
def [](index)
  raise_future_proof_exception unless finished?
  values[index]
end
finished?() click to toggle source

Checks if queue is stopped.

@return [true, false] true if queue is not working.

# File lib/future_proof/future_queue.rb, line 78
def finished?
  @finished
end
pop() click to toggle source

Pops value or raises an exception.

@return [Object] first value of queue.

@note allowed only when queue is running.

Calls superclass method
# File lib/future_proof/future_queue.rb, line 38
def pop
  raise_future_proof_exception if finished?
  raise_or_value super
end
push(*values, &block) click to toggle source

Pushes value into a queue by executing it. If execution results in an exception then exception is stored itself.

@note allowed only when queue is running.

Calls superclass method
# File lib/future_proof/future_queue.rb, line 19
def push(*values, &block)
  raise_future_proof_exception if finished?
  value = if block_given?
    begin
      block.call(*values)
    rescue => e
      e
    end
  else
    values.size == 1 ? values[0] : values
  end
  super(value)
end
start!() click to toggle source

Starts queue.

# File lib/future_proof/future_queue.rb, line 70
def start!
  @values   = nil
  @finished = false
end
stop!() click to toggle source

Stops queue.

# File lib/future_proof/future_queue.rb, line 65
def stop!
  @finished = true
end
values() click to toggle source

Returns FutureArray with all values.

@return [FutureProof::FutureArray] Array with values.

@note allowed only when queue is stopped.

# File lib/future_proof/future_queue.rb, line 48
def values
  raise_future_proof_exception unless finished?
  @values ||= FutureProof::FutureArray.new(instance_variable_get(:@que).dup)
end

Private Instance Methods

raise_future_proof_exception() click to toggle source

Raises an exception if queue is accessed in the wrong state.

# File lib/future_proof/future_queue.rb, line 85
def raise_future_proof_exception
  raise FutureProof::FutureProofException.new 'Queu is not accessible in the state given!'
end