Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ New library functions
Standard library changes
------------------------

* The `extrema` function now accepts a function argument in the same manner as `minimum` and
`maximum` ([#30323]).
* `hasmethod` can now check for matching keyword argument names ([#30712]).
* `startswith` and `endswith` now accept a `Regex` for the second argument ([#29790]).
* The `extrema` function now accepts a function argument in the same manner as `minimum` and
`maximum` ([#30323]).
* `hasmethod` can now check for matching keyword argument names ([#30712]).
* `startswith` and `endswith` now accept a `Regex` for the second argument ([#29790]).
* `retry` supports arbitrary callable objects ([#30382]).

#### LinearAlgebra

Expand Down Expand Up @@ -86,6 +87,7 @@ Deprecated or removed
[#30323]: https://github.com/JuliaLang/julia/issues/30323
[#30349]: https://github.com/JuliaLang/julia/issues/30349
[#30372]: https://github.com/JuliaLang/julia/issues/30372
[#30382]: https://github.com/JuliaLang/julia/issues/30382
[#30583]: https://github.com/JuliaLang/julia/issues/30583
[#30584]: https://github.com/JuliaLang/julia/issues/30584
[#30593]: https://github.com/JuliaLang/julia/issues/30593
Expand Down
7 changes: 5 additions & 2 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,16 @@ length(ebo::ExponentialBackOff) = ebo.n
eltype(::Type{ExponentialBackOff}) = Float64

"""
retry(f::Function; delays=ExponentialBackOff(), check=nothing) -> Function
retry(f; delays=ExponentialBackOff(), check=nothing) -> Function

Return an anonymous function that calls function `f`. If an exception arises,
`f` is repeatedly called again, each time `check` returns `true`, after waiting the
number of seconds specified in `delays`. `check` should input `delays`'s
current state and the `Exception`.

!!! compat "Julia 1.2"
Before Julia 1.2 this signature was restricted to `f::Function`.

# Examples
```julia
retry(f, delays=fill(5.0, 3))
Expand All @@ -237,7 +240,7 @@ retry(http_get, check=(s,e)->e.status == "503")(url)
retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)
```
"""
function retry(f::Function; delays=ExponentialBackOff(), check=nothing)
function retry(f; delays=ExponentialBackOff(), check=nothing)
(args...; kwargs...) -> begin
y = iterate(delays)
while y !== nothing
Expand Down
3 changes: 3 additions & 0 deletions test/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@ end
foo_kwargs(x; y=5) = x + y
@test retry(foo_kwargs)(3) == 8
@test retry(foo_kwargs)(3; y=4) == 7

# non-Functions
@test retry(Float64)(1) === 1.0
end