1{:ok, _} = Application.ensure_all_started(:logger) 2ExUnit.start() 3 4defmodule EvalConn do 5 use Connection 6 def init(fun) when is_function(fun, 0), do: fun.() 7 def init(state), do: {:ok, state} 8 9 def handle_call(:state, _, state), do: {:reply, state, state} 10 def handle_call(fun, from, state), do: fun.(from, state) 11 12 def handle_cast(fun, state), do: fun.(state) 13 14 def handle_info(:timeout, fun), do: fun.() 15 def handle_info(fun, state), do: fun.(state) 16 17 def connect(:backoff, fun), do: fun.() 18 def connect(fun, state), do: fun.(state) 19 20 def disconnect(fun, state), do: fun.(state) 21 22 def format_status(_, [pdict, state]) do 23 case Keyword.get(pdict, :format_status) do 24 nil -> state 25 fun -> fun.(state) 26 end 27 end 28 29 def terminate({:shutdown, fun}, state), do: fun.(state) 30 def terminate({:abnormal, fun}, state), do: fun.(state) 31 def terminate({{:nocatch, {:abnormal, fun}}, _}, state), do: fun.(state) 32 def terminate({{:abnormal, fun}, _}, state), do: fun.(state) 33end 34