Skip to content

Commit cfdf596

Browse files
authored
modify #84 for compatibility with julia >= 1.11 (#134)
1 parent b107907 commit cfdf596

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/implementation.jl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ end
191191
# NOTE: once v1.12 releases we should switch this to wait(t; throw=false)
192192
wait_nothrow(t) = Base._wait(t)
193193

194+
195+
"""
196+
empty_collection_error(task)
197+
198+
Check if a task failed due to an empty collection error.
199+
"""
200+
function empty_collection_error end
201+
202+
@static if VERSION < v"1.11.0-"
203+
function empty_collection_error(task)
204+
task.result isa MethodError && task.result.f == Base.mapreduce_empty
205+
end
206+
else
207+
function empty_collection_error(task)
208+
task.result isa ArgumentError &&
209+
task.result.msg ==
210+
"reducing over an empty collection is not allowed; consider supplying `init` to the reducer"
211+
end
212+
end
213+
194214
# GreedyScheduler w/o chunking
195215
function _tmapreduce(f,
196216
op,
@@ -230,7 +250,7 @@ function _tmapreduce(f,
230250
filtered_tasks = filter(tasks) do stabletask
231251
task = stabletask.t
232252
istaskdone(task) || wait_nothrow(task)
233-
if task.result isa MethodError && task.result.f == Base.mapreduce_empty
253+
if empty_collection_error(task)
234254
false
235255
else
236256
true
@@ -277,7 +297,7 @@ function _tmapreduce(f,
277297
filtered_tasks = filter(tasks) do stabletask
278298
task = stabletask.t
279299
istaskdone(task) || wait_nothrow(task)
280-
if task.result isa MethodError && task.result.f == Base.mapreduce_empty
300+
if empty_collection_error(task)
281301
false
282302
else
283303
true

0 commit comments

Comments
 (0)