Class: CLI::UI::WorkQueue::Future
- Inherits:
-
Object
- Object
- CLI::UI::WorkQueue::Future
- Defined in:
- lib/cli/ui/work_queue.rb
Instance Method Summary collapse
-
#complete(result) ⇒ Object
: (untyped result) -> void.
-
#completed? ⇒ Boolean
: -> bool.
-
#fail(error) ⇒ Object
: (Exception error) -> void.
-
#initialize ⇒ Future
constructor
: -> void.
-
#start ⇒ Object
: -> void.
-
#started? ⇒ Boolean
: -> bool.
-
#value ⇒ Object
: -> untyped.
Constructor Details
#initialize ⇒ Future
: -> void
9 10 11 12 13 14 15 16 |
# File 'lib/cli/ui/work_queue.rb', line 9 def initialize @mutex = Mutex.new #: Mutex @condition = ConditionVariable.new #: ConditionVariable @completed = false #: bool @started = false #: bool @result = nil #: untyped @error = nil #: Exception? end |
Instance Method Details
#complete(result) ⇒ Object
: (untyped result) -> void
19 20 21 22 23 24 25 |
# File 'lib/cli/ui/work_queue.rb', line 19 def complete(result) @mutex.synchronize do @completed = true @result = result @condition.broadcast end end |
#completed? ⇒ Boolean
: -> bool
49 50 51 |
# File 'lib/cli/ui/work_queue.rb', line 49 def completed? @mutex.synchronize { @completed } end |
#fail(error) ⇒ Object
: (Exception error) -> void
28 29 30 31 32 33 34 35 36 |
# File 'lib/cli/ui/work_queue.rb', line 28 def fail(error) @mutex.synchronize do return if @completed @completed = true @error = error @condition.broadcast end end |
#start ⇒ Object
: -> void
59 60 61 62 63 64 |
# File 'lib/cli/ui/work_queue.rb', line 59 def start @mutex.synchronize do @started = true @condition.broadcast end end |
#started? ⇒ Boolean
: -> bool
54 55 56 |
# File 'lib/cli/ui/work_queue.rb', line 54 def started? @mutex.synchronize { @started } end |
#value ⇒ Object
: -> untyped
39 40 41 42 43 44 45 46 |
# File 'lib/cli/ui/work_queue.rb', line 39 def value @mutex.synchronize do @condition.wait(@mutex) until @completed raise @error if @error @result end end |