Skip to content

Commit e6f8180

Browse files
Rory Finneganararslan
Rory Finnegan
authored andcommitted
Added kwargs support to retry. (#21419)
* Added kwargs support to `retry`. * Updated retry example in doc string and added a couple tests.
1 parent 3a47d4e commit e6f8180

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

base/error.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ retry(f, delays=fill(5.0, 3))
128128
retry(f, delays=rand(5:10, 2))
129129
retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000))
130130
retry(http_get, check=(s,e)->e.status == "503")(url)
131-
retry(read, check=(s,e)->isa(e, UVError))(io)
131+
retry(read, check=(s,e)->isa(e, UVError))(io, 128; all=false)
132132
```
133133
"""
134134
function retry(f::Function; delays=ExponentialBackOff(), check=nothing)
135-
(args...) -> begin
135+
(args...; kwargs...) -> begin
136136
state = start(delays)
137137
while true
138138
try
139-
return f(args...)
139+
return f(args...; kwargs...)
140140
catch e
141141
done(delays, state) && rethrow(e)
142142
if check !== nothing

test/error.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ let
6363
@test typeof(ex) == ErrorException
6464
@test ex.msg == "foo"
6565
@test c[1] == 1
66+
67+
# Functions with keyword arguments
68+
foo_kwargs(x; y=5) = x + y
69+
@test retry(foo_kwargs)(3) == 8
70+
@test retry(foo_kwargs)(3; y=4) == 7
6671
end

0 commit comments

Comments
 (0)