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
# File lib/future_proof/future_queue.rb, line 9 def initialize @finished = false super() end
Public Instance Methods
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
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
Pops value or raises an exception.
@return [Object] first value of queue.
@note allowed only when queue is running.
# File lib/future_proof/future_queue.rb, line 38 def pop raise_future_proof_exception if finished? raise_or_value super end
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.
# 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
Starts queue.
# File lib/future_proof/future_queue.rb, line 70 def start! @values = nil @finished = false end
Stops queue.
# File lib/future_proof/future_queue.rb, line 65 def stop! @finished = true end
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
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