After-commit hook?
I'm running into a race condition issue when I insert a row to a table with the resource's create action, and the subscriber to the notification calculates the resulting row count. What's the right way to do this in Ash? Adding 'Process.sleep(1000)' seems to help but I'm hoping there is a better way. Thanks.
5 Replies
is that the kind of thing you're looking for?
Tried it by putting the broadcast statement inside the after_action block but still had the race condition issue. (ie. the subscriber's row count doesn't include the newly inserted row). I need a way for the broadcast to happen after the change is committed to the database.
Are you manually publishing events over pubsub?
Why not use the pubsub notifier that is built in?
https://hexdocs.pm/ash/Ash.Notifier.PubSub.html
There are after transaction hooks too
But you should prefer to use notifiers for this purpose
I was actually looking into it. Is there a broadcast_type that allows for an output very simple like that of 'Phoenix.PubSub.broadcast(MyApp.PubSub, "inbox:user_id", {:inbox_updated, nil})? I tried all broadcast_types but their outputs are more complex data structures like structs.
You would want a transform on the pubsub broadcast then
https://hexdocs.pm/ash/dsl-ash-notifier-pubsub.html#pub_sub-transform