Skip to content

Commit

Permalink
Merge pull request #366 from trainual/run_deferred_callbacks_after_or…
Browse files Browse the repository at this point in the history
…ganizer_perform

Defer until after `perform` instead of `all_perform`
  • Loading branch information
aaronmallen authored Sep 30, 2023
2 parents 9b7be5e + 511647e commit 040dea0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lib/active_interactor/interactor/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ def execute_context!
end

def execute_context_with_callbacks!
interactor.run_callbacks :perform do
result = interactor.run_callbacks :perform do
execute_context_with_validation_check!
@context = interactor.finalize_context!
end

if context&.success? && interactor.respond_to?(:run_deferred_after_perform_callbacks_on_children)
interactor.run_deferred_after_perform_callbacks_on_children
end

result
end

def execute_context_with_validation!
Expand Down
17 changes: 8 additions & 9 deletions lib/active_interactor/organizer/perform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ def perform
perform_in_order
end
end
run_after_perform_callbacks_on_interactors if context.success?
end

def run_deferred_after_perform_callbacks_on_children
self.class.organized.each do |interface|
next unless interface.interactor_class.after_callbacks_deferred_when_organized

context.merge!(interface.execute_deferred_after_perform_callbacks(context))
end
end

private
Expand Down Expand Up @@ -100,14 +107,6 @@ def perform_in_parallel
end
merge_contexts(results.map(&:value))
end

def run_after_perform_callbacks_on_interactors
self.class.organized.each do |interface|
next unless interface.interactor_class.after_callbacks_deferred_when_organized

context.merge!(interface.execute_deferred_after_perform_callbacks(context))
end
end
end
end
end

0 comments on commit 040dea0

Please sign in to comment.