Class: CLI::UI::WorkQueue::Future
- Inherits:
-
Object
- Object
- CLI::UI::WorkQueue::Future
- Extended by:
- T::Sig
- Defined in:
- lib/cli/ui/work_queue.rb
Instance Method Summary collapse
- #complete(result) ⇒ Object
- #completed? ⇒ Boolean
- #fail(error) ⇒ Object
-
#initialize ⇒ Future
constructor
A new instance of Future.
- #start ⇒ Object
- #started? ⇒ Boolean
- #value ⇒ Object
Methods included from T::Sig
Constructor Details
#initialize ⇒ Future
Returns a new instance of Future.
13 14 15 16 17 18 19 20 |
# File 'lib/cli/ui/work_queue.rb', line 13 def initialize @mutex = T.let(Mutex.new, Mutex) @condition = T.let(ConditionVariable.new, ConditionVariable) @completed = T.let(false, T::Boolean) @started = T.let(false, T::Boolean) @result = T.let(nil, T.untyped) @error = T.let(nil, T.nilable(Exception)) end |
Instance Method Details
#complete(result) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/cli/ui/work_queue.rb', line 23 def complete(result) @mutex.synchronize do @completed = true @result = result @condition.broadcast end end |
#completed? ⇒ Boolean
53 54 55 |
# File 'lib/cli/ui/work_queue.rb', line 53 def completed? @mutex.synchronize { @completed } end |
#fail(error) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/cli/ui/work_queue.rb', line 32 def fail(error) @mutex.synchronize do return if @completed @completed = true @error = error @condition.broadcast end end |
#start ⇒ Object
63 64 65 66 67 68 |
# File 'lib/cli/ui/work_queue.rb', line 63 def start @mutex.synchronize do @started = true @condition.broadcast end end |
#started? ⇒ Boolean
58 59 60 |
# File 'lib/cli/ui/work_queue.rb', line 58 def started? @mutex.synchronize { @started } end |
#value ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/cli/ui/work_queue.rb', line 43 def value @mutex.synchronize do @condition.wait(@mutex) until @completed raise @error if @error @result end end |