You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps not so much a bug as undocumented and potentially undesirable behavior, but:
Issue
When iterating over a lazily-computed sequence such as a generator, asyncmap computes all of the elements of that sequence within a single task. Here's a minimal working example:
taskoid() =objectid(current_task())
seq = (taskoid() for _ ineachline("/path/to/text/file"))
task_ids =asyncmap(seq; ntasks=10) do x
x
end
At the end of this code, task_ids contains the id of a single task, indicating that every element of seq was computed within the same task.
Expected behavior
It would probably make more sense for the ith element of seq to be calculated by the task that operates on it. This would support some richer ways in which to use asyncmap. For instance, here's an example using HTTP.jl and Transducers.jl to query a list of URLs and report which ones returned a 200 status code:
using HTTP
using Transducers
filtered_responses =eachline("urls.txt") |>Map(u -> HTTP.get(e); status_exception =false) |>Filter(r -> r.status ==200)
asyncmap(filtered_responses; ntasks=5) do r
println(r.request.target)
end
The current implementation of asyncmap causes each call to HTTP.get to run in the same task, rather than concurrently. It'd probably be preferable for the call to asyncmap above to work more like this:
@syncfor _ =1:5@asyncfor r in filtered_responses
println(r.request.target)
endend
Additional info
Julia version: 1.5.2
The text was updated successfully, but these errors were encountered:
Perhaps not so much a bug as undocumented and potentially undesirable behavior, but:
Issue
When iterating over a lazily-computed sequence such as a generator,
asyncmap
computes all of the elements of that sequence within a single task. Here's a minimal working example:At the end of this code,
task_ids
contains the id of a single task, indicating that every element ofseq
was computed within the same task.Expected behavior
It would probably make more sense for the
i
th element ofseq
to be calculated by the task that operates on it. This would support some richer ways in which to useasyncmap
. For instance, here's an example using HTTP.jl and Transducers.jl to query a list of URLs and report which ones returned a 200 status code:The current implementation of
asyncmap
causes each call toHTTP.get
to run in the same task, rather than concurrently. It'd probably be preferable for the call toasyncmap
above to work more like this:Additional info
The text was updated successfully, but these errors were encountered: