Skip to content

Commit

Permalink
retry should support the check function proposed in the docstring. (J…
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn authored and JeffBezanson committed Feb 27, 2018
1 parent 3ae519d commit 13f42e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ function retry(f::Function; delays=ExponentialBackOff(), check=nothing)
catch e
done(delays, state) && rethrow(e)
if check !== nothing
state, retry_or_not = check(state, e)
result = check(state, e)
state, retry_or_not = length(result) == 2 ? result : (state, result)
retry_or_not || rethrow(e)
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ end
@test ex.msg == "foo"
@test c[1] == 1

# Test example in docstring where the check function doesn't return the state.
c = [0]
@test retry(foo_error, check=(s,e)->e.msg == "foo")(c,1) == 7
@test c[1] == 2

# Functions with keyword arguments
foo_kwargs(x; y=5) = x + y
@test retry(foo_kwargs)(3) == 8
Expand Down

0 comments on commit 13f42e6

Please sign in to comment.