Help my memory - I’m sure I saw a nice macro somewhere that added an until construct to Elixir,
What i want to do is pretty basic :
# until function returns true, ignore exceptions, block for maximum of 60 seconds.
until(Foo.check_is_something_good, 60_000)
Just like this linux command :
- until curl \
--silent \
-XGET \
--fail http://127.0.0.1:${EX_RABBIT_POOL_PORT} &> /dev/null \
; do printf '.'; sleep 1; done
I know I could code this in a short time but I keep encountering this same need - wonder if there’s anything pretty out there.
Thanks.
B
You basically just get this for free with tasks:
task = Task.async(fn -> Foo.check_is_good() end)
Task.yield(task, 60_000)
4 Likes
What am I missing?
I don’t see that working unless Foo.check_is_good()
is actually Foo.return_when_good()
- i.e. yield/2
in the docs doesn’t seem to imply any looping behaviour - so the looping (e.g. recursing) behaviour would have to be built into the function (task) being called.
Here I simply wrote a wait/3
function for the desired effect.
1 Like
Solved @IanLuites with_retry - does everything I need and everything I could ever need - thanks
1 Like
Happy that it can be of use. Let me know if anything doesn’t work or is unclear!
(I myself am mostly unhappy with the way backoff/config is passed)