class ObjectFramework::Capabilities::IsolatedTask
Runs a class/moduleโs +self.call(input)+ in a new Ractor over independent values. Sessions and execution contexts stay on the owning request thread.
Public Class Methods
Source
# File lib/object_framework/capabilities.rb, line 43 def initialize(task:) raise ConfigurationError, "An isolated task must be a class or module implementing call" unless task.is_a?(Module) && task.respond_to?(:call) @task = task end
Public Instance Methods
Source
# File lib/object_framework/capabilities.rb, line 52 def call(input, context: nil) context&.cancellation&.check! payload = Values.detach(input) # Only independent values cross this boundary; the request keeps its session. ractor = Ractor.new(@task, payload) do |task, values| begin [:success, ObjectFramework::Values.detach(task.call(values))] rescue StandardError => error [:failure, error.class.name, error.message, error.backtrace] end end outcome, *result = ractor.value context&.cancellation&.check! if outcome == :failure raise TaskFailure.new(remote_class: result[0], message: result[1], backtrace: result[2]) end Values.detach(result.first) end
Returns a detached task result. Checks optional context cancellation before and after the computation; cannot interrupt a running Ractor. Remote StandardError failures become TaskFailure with the remote class name and backtrace. Use bounded computations.