OeditusCredo.Check.Warning.MissingHandleAsync
(OeditusCredo v0.6.0)
View Source
Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of normal and works with any version of Elixir.
Explanation
LiveView handle_event with blocking operations should use start_async and handle_async.
This prevents blocking the LiveView process and provides better UX.
Bad:
def handle_event("load", _params, socket) do
data = Repo.all(Post)
{:noreply, assign(socket, :posts, data)}
endGood:
def handle_event("load", _params, socket) do
{:noreply, start_async(socket, :posts, fn -> Repo.all(Post) end)}
end
def handle_async(:posts, {:ok, posts}, socket) do
{:noreply, assign(socket, :posts, posts)}
endCheck-Specific Parameters
Use the following parameters to configure this check:
:exclude_test_files
Set to true to skip test files (default: false)
This parameter defaults to nil.
:extra_blocking_modules
Additional module atoms to treat as blocking (default: [])
This parameter defaults to nil.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.