From 911acdef5b0716c06a018738224ec4775697261f Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Wed, 12 Apr 2023 18:10:17 -0400 Subject: [PATCH] chore: better notification handling --- lib/ash/engine/engine.ex | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/ash/engine/engine.ex b/lib/ash/engine/engine.ex index 17155731..c8030ed9 100644 --- a/lib/ash/engine/engine.ex +++ b/lib/ash/engine/engine.ex @@ -124,15 +124,21 @@ defmodule Ash.Engine do ) |> case do {:ok, result} -> - saved_notifications = Process.delete(:ash_engine_notifications) - remaining_notifications = Ash.Notifier.notify(saved_notifications) + saved_notifications = Process.delete(:ash_engine_notifications) || [] - {:ok, - %{ - result - | resource_notifications: - result.resource_notifications ++ remaining_notifications - }} + if opts[:return_notifications?] do + {:ok, + %{ + result + | resource_notifications: + result.resource_notifications ++ saved_notifications + }} + else + remaining_notifications = + Ash.Notifier.notify(result.resource_notifications ++ saved_notifications) + + {:ok, %{result | resource_notifications: remaining_notifications}} + end {:error, error} -> {:error, error}