Here is the correct code:
function getImages()
myimages = Vector{Any}(undef, 30)
# instead of Any use the correct type of whatever your load returns
@sync for i in 1:30
@async myimages[i] = load("path/to/image$i.jpg");
end
myimages
end
This approach is usefull when your IO is slow.
Note however that this coode is going to utilize only a single thread. Hence if not IO is your performance bottleneck such parallelization will not help. In that case you should consider using threads.
Before starting Julia run:
set JULIA_NUM_THREADS=4
or on Linux
export JULIA_NUM_THREADS=4
And change your function to:
function getImages()
myimages = Vector{Any}(undef, 30)
# instead of Any use the correct type of whatever your load returns
Threads.@threads for i in 1:30
myimages[i] = load("path/to/image$i.jpg");
end
myimages
end