Class: Phronomy::Task::Backend
- Inherits:
-
Object
- Object
- Phronomy::Task::Backend
- Defined in:
- lib/phronomy/task/backend.rb
Overview
Abstract base class for Task execution backends.
A backend encapsulates the execution primitive (Thread, Fiber, etc.) and the lifecycle transitions it drives. Concrete backends must implement all abstract methods. The default concrete implementation is ThreadBackend.
Backends receive a reference to the owning Phronomy::Task so they can call #transition! at the appropriate lifecycle points.
Direct Known Subclasses
Instance Method Summary collapse
-
#alive? ⇒ Boolean
private
Returns +true+ while execution is still ongoing.
-
#await ⇒ Object
private
Blocks until the task completes and returns its value.
-
#cancel! ⇒ self
private
Requests cancellation.
-
#completed_error ⇒ Exception?
private
Returns the exception raised by the task, or +nil+ on success/cancellation.
-
#completed_value ⇒ Object?
private
Returns the task's result value once it has reached a terminal state.
-
#initialize(task:, &block) ⇒ Backend
constructor
private
A new instance of Backend.
-
#join(limit = nil) ⇒ Object?
private
Joins the execution context with an optional timeout.
Constructor Details
#initialize(task:, &block) ⇒ Backend
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Backend.
17 18 19 20 |
# File 'lib/phronomy/task/backend.rb', line 17 def initialize(task:, &block) @task = task @block = block end |
Instance Method Details
#alive? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns +true+ while execution is still ongoing.
34 35 36 |
# File 'lib/phronomy/task/backend.rb', line 34 def alive? raise NotImplementedError, "#{self.class}#alive? not implemented" end |
#await ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Blocks until the task completes and returns its value. Re-raises errors from the block.
27 28 29 |
# File 'lib/phronomy/task/backend.rb', line 27 def await raise NotImplementedError, "#{self.class}#await not implemented" end |
#cancel! ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Requests cancellation. Thread-based backends may use +Thread#raise+; cooperative backends should mark the task cancelled and rely on Phronomy::Task.checkpoint!.
43 44 45 |
# File 'lib/phronomy/task/backend.rb', line 43 def cancel! raise NotImplementedError, "#{self.class}#cancel! not implemented" end |
#completed_error ⇒ Exception?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the exception raised by the task, or +nil+ on success/cancellation. Only valid to call after the task is done. Subclasses should override if they store errors.
71 72 73 |
# File 'lib/phronomy/task/backend.rb', line 71 def completed_error nil end |
#completed_value ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the task's result value once it has reached a terminal state. Only valid to call after the task is done. Subclasses should override if they store the result.
62 63 64 |
# File 'lib/phronomy/task/backend.rb', line 62 def completed_value nil end |
#join(limit = nil) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Joins the execution context with an optional timeout. Returns +nil+ when a non-nil +limit+ expires before completion, matching +Thread#join+ semantics.
53 54 55 |
# File 'lib/phronomy/task/backend.rb', line 53 def join(limit = nil) raise NotImplementedError, "#{self.class}#join not implemented" end |