Skip to content

Conversation

@nirev
Copy link
Contributor

@nirev nirev commented Nov 11, 2025

This PR adds :ok as an accepted result for the fun passed to Repo.transact/2.

It is sometimes useful to return just :ok when you don't care about the results of the function, just that the sequence of operations executed successfully.

Eg:

def do_something do
  Repo.transact(fn -> 
    {:ok, x} = get_x_with_lock()
    {:ok, _} = update_all_records(x)
    
     :ok
  end)
end

@warmwaffles
Copy link
Member

In practice I've had to do {:ok, :ok} to achieve this or just return something. Typically though I've thought of it as forcing you to think about the side effect that is being caused and having to conciously return the meaningful mutation.

@nirev nirev closed this Nov 11, 2025
@nirev
Copy link
Contributor Author

nirev commented Nov 11, 2025

Closed this as I realized this would implicate in way more changes than it was worth it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants