Class: PromptObjects::Execution::CancellationToken
- Inherits:
-
Object
- Object
- PromptObjects::Execution::CancellationToken
- Defined in:
- lib/prompt_objects/execution/context.rb
Overview
Cooperative cancellation shared by a run and its attached descendants.
Instance Method Summary collapse
- #cancel(reason = "cancelled") ⇒ Object
- #cancelled? ⇒ Boolean
- #check! ⇒ Object
-
#initialize ⇒ CancellationToken
constructor
A new instance of CancellationToken.
- #reason ⇒ Object
Constructor Details
#initialize ⇒ CancellationToken
Returns a new instance of CancellationToken.
9 10 11 12 13 |
# File 'lib/prompt_objects/execution/context.rb', line 9 def initialize @cancelled = false @reason = nil @mutex = Mutex.new end |
Instance Method Details
#cancel(reason = "cancelled") ⇒ Object
15 16 17 18 19 20 |
# File 'lib/prompt_objects/execution/context.rb', line 15 def cancel(reason = "cancelled") @mutex.synchronize do @cancelled = true @reason = reason end end |
#cancelled? ⇒ Boolean
22 23 24 |
# File 'lib/prompt_objects/execution/context.rb', line 22 def cancelled? @mutex.synchronize { @cancelled } end |
#check! ⇒ Object
30 31 32 |
# File 'lib/prompt_objects/execution/context.rb', line 30 def check! raise CancelledError, reason if cancelled? end |
#reason ⇒ Object
26 27 28 |
# File 'lib/prompt_objects/execution/context.rb', line 26 def reason @mutex.synchronize { @reason } end |