-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Description
MWE:
julia> using StructArrays
# asyncmap() with sleep() inside returns nothings:
julia> asyncmap(StructArray(a=[1,2,3])) do x
sleep(1)
"abc $x"
end
3-element Vector{Nothing}:
nothing
nothing
nothing
# fine without sleep():
julia> asyncmap(StructArray(a=[1,2,3])) do x
"abc $x"
end
3-element Vector{String}:
"abc (a = 1,)"
"abc (a = 2,)"
"abc (a = 3,)"
# fine with map() instead of asyncmap():
julia> map(StructArray(a=[1,2,3])) do x
sleep(1)
"abc $x"
end
3-element Vector{String}:
"abc (a = 1,)"
"abc (a = 2,)"
"abc (a = 3,)"The bug seems to be in asyncmap, it assumes too much about the collection. asyncmap works like this:
- create array of
Refs inLine 155 in 95f30e5
asyncrun = map(wrapped_f, c...) - loop over these
Refs (in multiple tasks, but the multi-task aspect doesn't matter) - mutate
ref.xto store the resulting elementLine 94 in 95f30e5
exec_func = (r,args) -> (r.x = f(args...))
In the MWE above with StructArrays, the asyncrun variable is naturally also a StructArray (it results from map). But extracting an element from a StructArray creates a new object, not a copy – no way around it. So, the r.x = ... assignment doesn't mutate anything in the resulting array that gets returned.
I guess, to be generic, the Channel should store indices in the original array instead of elements?
Metadata
Metadata
Assignees
Labels
No labels