Hi, I have build a application where I have a function which collect data from a API call then store it to a Array as follows:
using DotEnv, HTTP, JSON3
DotEnv.config();
# Function to collect data
function collect_data(method, url, token, body)
r = HTTP.request(
method,
url,
["Content-Type" => "application/json", "X-Token" => ENV["HERA_SECRET"]],
JSON3.write(body),
require_ssl_verification = false
)
if isequal(r.status, 200)
try
return JSON3.read(r.body)["data"]
catch err
println("Error while parsing: $err")
end
end
return Dict()
end
# A preallocated array
linear_data = Array{Any}(undef, 1000);
# linear call to API
for i in 1:1000
linear_data[i] = collect_data("POST", URL, ENV["HERA_SECRET"], params);
end
But I want to convert that in to Async call. But to use Distributed jl probably I need a shared array. But shared array do not support the type Any. My plan was to create an array
using Distributed, SharedArrays
# Add Processes
addprocs(n)
# Shared array does not support Any type
non_linear_data = SharedArray{Any}(1000)
@sync @distributed for i in 1:1000
non_linear_data[i] = collect_data("POST", URL, ENV["HERA_SECRET"], params);
end
But I am stuck at the distributed part. Is there any better way to resolve that? In Go that would be easy to create a Bidirectional Channel and feed the result into the Channel and later collect the data from the Channel into a slice.