I have a loop that retries creating a socket when there is an exception. I want to return that socket if there is a successful creation of that socket, otherwise retry.
I want the loop to evaluate to the thing inside the loop, the number 6 in this example, my code resembles the following:
(loop []
(when-not
(try
6
(catch Exception e
(.println *err* (str e))
false
)
)
(recur)
)
)
This currently returns nil. How do I make this block return 6? (In my real code, the code is a socket creation and can throw an exception)
jepsen.etcdemo=> (loop []
#_=> (when-not
#_=> (try
#_=> 6
#_=>
#_=> (catch Exception e
#_=> (.println *err* (str e))
#_=> false
#_=> )
#_=> )
#_=> (recur)
#_=> )
#_=> )
nil