lib/attr/gather/workflow/task_execution_result.rb in attr-gather-1.1.2 vs lib/attr/gather/workflow/task_execution_result.rb in attr-gather-1.1.3

- old
+ new

@@ -18,15 +18,15 @@ class TaskExecutionResult include Concerns::Identifiable attr_reader :task, :result, :started_at, :uuid - def initialize(task, result) - @started_at = Time.now - @uuid = SecureRandom.uuid + def initialize(task, result, started_at: Time.now, uuid: SecureRandom.uuid) # rubocop:disable Metrics/LineLength @task = task @result = result + @started_at = started_at + @uuid = uuid end # @!attribute [r] state # @return [:unscheduled, :pending, :processing, :rejected, :fulfilled] def state @@ -39,9 +39,28 @@ # @note For more information, check out {https://ruby-concurrency.github.io/concurrent-ruby/1.1.5/Concurrent/Concern/Obligation.html#value!-instance_method} def value! result.value! end + # Chain a new block result to be executed after resolution + # + # @return [TaskExecutionResult] the new task execution result + # @yield The block operation to be performed asynchronously. + def then(*args, &block) + new_result = result.then(*args, &block) + self.class.new(task, new_result, started_at: @started_at, uuid: @uuid) + end + + # Catch an async exception when a failure occurs + # + # @return [TaskExecutionResult] the new task execution result + # @yield The block operation to be performed asynchronously. + def catch(*args, &block) + new_result = result.catch(*args, &block) + self.class.new(task, new_result, started_at: @started_at, uuid: @uuid) + end + + # Executes a block after the result is fulfilled # Represents the TaskExecutionResult as a hash # # @return [Hash] def as_json value = result.value