Class: FutureProof::FutureQueue
- Inherits:
-
Queue
- Object
- Queue
- FutureProof::FutureQueue
- Includes:
- Exceptionable
- Defined in:
- lib/future_proof/future_queue.rb
Overview
FutureQueue
is designed to handle exceptions that happen in a threads. It raises an exception when user tries to access “exceptional” value.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Returns
FutureArray
with all values. -
#finished? ⇒ true, false
Checks if queue is stopped.
-
#initialize ⇒ FutureQueue
constructor
A new instance of FutureQueue.
-
#pop ⇒ Object
Pops value or raises an exception.
-
#push(*values, &block) ⇒ Object
Pushes value into a queue by executing it.
-
#start! ⇒ Object
Starts queue.
-
#stop! ⇒ Object
Stops queue.
-
#values ⇒ FutureProof::FutureArray
Returns
FutureArray
with all values.
Constructor Details
#initialize ⇒ FutureQueue
Returns a new instance of FutureQueue.
9 10 11 12 |
# File 'lib/future_proof/future_queue.rb', line 9 def initialize @finished = false super() end |
Instance Method Details
#[](index) ⇒ Object
allowed only when queue is stopped.
raises an exception if it happened during execution.
Returns FutureArray
with all values.
59 60 61 62 |
# File 'lib/future_proof/future_queue.rb', line 59 def [](index) raise_future_proof_exception unless finished? values[index] end |
#finished? ⇒ true, false
Checks if queue is stopped.
78 79 80 |
# File 'lib/future_proof/future_queue.rb', line 78 def finished? @finished end |
#pop ⇒ Object
allowed only when queue is running.
Pops value or raises an exception.
38 39 40 41 |
# 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) ⇒ Object
allowed only when queue is running.
Pushes value into a queue by executing it. If execution results in an exception then exception is stored itself.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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! ⇒ Object
Starts queue.
70 71 72 73 |
# File 'lib/future_proof/future_queue.rb', line 70 def start! @values = nil @finished = false end |
#stop! ⇒ Object
Stops queue.
65 66 67 |
# File 'lib/future_proof/future_queue.rb', line 65 def stop! @finished = true end |
#values ⇒ FutureProof::FutureArray
allowed only when queue is stopped.
Returns FutureArray
with all values.
48 49 50 51 |
# 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 |