I’ve been struggling with this for a few hours now and there must be an easy answer despite my inability to search and find answers.
So I have this pretty simple code:
def tcp_port_open?(host, port) do
case :gen_tcp.connect(String.to_charlist(host), port, []) do
{:ok, socket} ->
:gen_tcp.close(socket)
true
{:error, _} ->
false
end
end
def wait_for_true(fun), do: wait_for_true(fun, 10_000)
def wait_for_true(_fun, 0), do: false
def wait_for_true(fun, timeout) do
case fun.() do
true ->
true
false ->
:timer.sleep(100)
wait_for_true(fun, max(0, timeout - 100))
end
end
I’m not sure how to call wait_for_true
passing the captured named function tcp_port_open?
that needs args.
I’ve tried a few things but they all require Mod.fun/arity or local_fun/arity. Not sure how to pass arguments into the function like so:
wait_for_true(&tcp_port_open?("localhost", 4001))
Thanks!