Class: PromptObjects::Execution::Scheduler::Ticket
- Inherits:
-
Object
- Object
- PromptObjects::Execution::Scheduler::Ticket
- Defined in:
- lib/prompt_objects/execution/scheduler.rb
Instance Attribute Summary collapse
-
#run_id ⇒ Object
readonly
Returns the value of attribute run_id.
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(run_id) ⇒ Ticket
constructor
A new instance of Ticket.
- #reject(error) ⇒ Object
- #resolve(value) ⇒ Object
- #wait(timeout: nil) ⇒ Object
Constructor Details
#initialize(run_id) ⇒ Ticket
Returns a new instance of Ticket.
17 18 19 20 21 22 23 24 |
# File 'lib/prompt_objects/execution/scheduler.rb', line 17 def initialize(run_id) @run_id = run_id @mutex = Mutex.new @condition = ConditionVariable.new @complete = false @value = nil @error = nil end |
Instance Attribute Details
#run_id ⇒ Object (readonly)
Returns the value of attribute run_id.
26 27 28 |
# File 'lib/prompt_objects/execution/scheduler.rb', line 26 def run_id @run_id end |
Instance Method Details
#complete? ⇒ Boolean
43 44 45 |
# File 'lib/prompt_objects/execution/scheduler.rb', line 43 def complete? @mutex.synchronize { @complete } end |
#reject(error) ⇒ Object
51 52 53 |
# File 'lib/prompt_objects/execution/scheduler.rb', line 51 def reject(error) finish(error: error) end |
#resolve(value) ⇒ Object
47 48 49 |
# File 'lib/prompt_objects/execution/scheduler.rb', line 47 def resolve(value) finish(value: value) end |
#wait(timeout: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prompt_objects/execution/scheduler.rb', line 28 def wait(timeout: nil) deadline = timeout && monotonic_time + timeout @mutex.synchronize do until @complete remaining = deadline && deadline - monotonic_time raise Timeout::Error, "run #{@run_id} did not finish" if remaining && !remaining.positive? @condition.wait(@mutex, remaining) end raise @error if @error @value end end |