OeditusCredo.Check.Warning.SyncOverAsync (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 high and works with any version of Elixir.

Explanation

Blocking operations in LiveView event handlers or GenServer callbacks cause performance issues.

Offload expensive operations to async tasks or background jobs.

Bad:

def handle_event("save", params, socket) do
  user = Repo.get!(User, params["id"])
  {:noreply, assign(socket, :user, user)}
end

Good:

def handle_event("save", params, socket) do
  socket = assign_async(socket, :user, fn ->
    {:ok, %{user: Repo.get!(User, params["id"])}}
  end)
  {:noreply, socket}
end

Check-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.

:callback_functions

Callback function names to check (default: [:handle_event, :handle_call, :handle_info, :handle_cast, :handle_continue])

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.