Skip to content

Commit

Permalink
Make task_module a compile_env
Browse files Browse the repository at this point in the history
  • Loading branch information
drtheuns committed Dec 8, 2024
1 parent f1cd148 commit da38066
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/absinthe/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,18 @@ defmodule Absinthe.Utils do
"""
end

task_module = Application.compile_env(:absinthe, :task_module)

@spec async((-> any)) :: Task.t()
def async(fun) do
case Application.fetch_env(:absinthe, :task_module) do
{:ok, module} when is_atom(module) ->
module.async(fun)
cond do
is_atom(task_module) and task_module != nil ->
def async(fun), do: unquote(task_module).async(fun)

_ ->
async_default(fun)
end
end
# Optionally use `async/1` function from `opentelemetry_process_propagator` if available
Code.ensure_loaded?(OpentelemetryProcessPropagator.Task) ->
defdelegate async(fun), to: OpentelemetryProcessPropagator.Task

# Optionally use `async/1` function from `opentelemetry_process_propagator` if available
if Code.ensure_loaded?(OpentelemetryProcessPropagator.Task) do
@spec async_default((-> any)) :: Task.t()
defdelegate async_default(fun), to: OpentelemetryProcessPropagator.Task, as: :async
else
@spec async_default((-> any)) :: Task.t()
defdelegate async_default(fun), to: Task, as: :async
true ->
defdelegate async(fun), to: Task
end
end

0 comments on commit da38066

Please sign in to comment.