I’ve been using this in my small app for a little bit and have noticed a decent reduction in the number of WTF errors w/ HTTPoison. In a production system HTTP requests are extremely failure prone and I’ve found that simply retrying the request after a small timeout fixes the problem. I’ve received everything from inabilities to resolve domain names (that clearly exist) to 500 errors from Amazon S3.
So I thought about that a bit. The macro does end up wrapping it into a function internally, but the DSL wouldn’t flow very well if it required wrapping the input in a function. I’d imagine the code would look like this if it accepted a function instead…
fn -> HTTPoison.get("www.example.com") end
|> autoretry()
|> handle_response
I feel like that would lead to less readability and more confusion in general. How would you expect it to look using a function?
AH I see. I would 100% expect a literal function definition instead of a macro based one. That’s how Task, spawn, and a host of other functions like it work. What you have isn’t hideous but quite possibly you just do
Did you consider using Retry in your package? Retry is quite configurable and has support for linear and exponential backoff strategies, among other things.