4 ms·
var result = ?, err = NeverEvenTriedError for attempt_no := 1 to retry_count + 1 do result, err := action() while err and is_transient_error
by Joker_vD 1y ago
var result = ?, err = NeverEvenTriedError
for attempt_no := 1 to retry_count + 1 do
result, err := action()
while err and is_transient_error(err)
between
sleep()
end
where the "between" block is inserted "between" the iterations or more precisely, it is run before the loop's body for every iteration other than the very first one (after the increment part is executed), so if you put e.g. "print(attempt_no)" in there, it would print 2, 3, etc. up to and including retry_count + 1.
IMHO, such a block would be more useful than the "else" block in loops, although of course, you can always emulate it as
var result = ?, err = NeverEvenTriedError
for attempt_no := 1 to retry_count + 1 do
result, err := action()
while err and is_transient_error(err)
if (attempt_no = 1) then continue
sleep()
end
- 1718627440 1y agoIs there a language, that has this between keyword?
- Joker_vD 1y agoWell, no. But I think it wouldn't be that hard to add to e.g. Golang, the code gen for this feature is pretty small: find the closest wrapping loop, put "$unique_name := true" as the first statement of its body, replace the keyword itself with "if ($unique_name) { $unique_name = false; continue; }" node.
- 1718627440 1y agoSure. You can also simply put what you want to be executed after the condition behind the condition. You could also invent a 4-ary for ( for(init; condition; between; increment) ), but you can also do that with a macro.