Class: LittleGhost::Subagents::Manager::Completion
- Inherits:
-
Object
- Object
- LittleGhost::Subagents::Manager::Completion
- Defined in:
- lib/little_ghost/subagents/manager.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize ⇒ Completion
constructor
A new instance of Completion.
- #reject(error) ⇒ Object
- #resolve(value) ⇒ Object
- #value(cancellation_token: nil, deadline: nil) ⇒ Object
Constructor Details
#initialize ⇒ Completion
Returns a new instance of Completion.
107 108 109 110 111 |
# File 'lib/little_ghost/subagents/manager.rb', line 107 def initialize @mutex = Mutex.new @condition = ConditionVariable.new @resolved = false end |
Instance Method Details
#reject(error) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/little_ghost/subagents/manager.rb', line 123 def reject(error) @mutex.synchronize do return if @resolved @error = error @resolved = true @condition.broadcast end end |
#resolve(value) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/little_ghost/subagents/manager.rb', line 113 def resolve(value) @mutex.synchronize do return if @resolved @value = value @resolved = true @condition.broadcast end end |
#value(cancellation_token: nil, deadline: nil) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/little_ghost/subagents/manager.rb', line 133 def value(cancellation_token: nil, deadline: nil) @mutex.synchronize do until @resolved cancellation_token&.raise_if_cancelled! if deadline && Time.now >= deadline raise DeadlineExceededError, "The run deadline was reached" end timeout = deadline ? [deadline - Time.now, 0.05].min : 0.05 @condition.wait(@mutex, [timeout, 0].max) end raise @error if @error @value end end |