Discussion:
[elm-discuss] Parallel http queries: how?
Vadym Chekan
2017-11-21 20:14:55 UTC
Permalink
Hi all,

My app needs to get data from 2 sources upon initialization. Those two data
sources are independent and can be queried in parallel. How do I do it?
I tried to use RemoteData.map2, but it consumes RemoteData structures and I
do not know how to produce it because sendQuery produces command and most
of the functions produce commands and not RemoteData.
I perhaps can do it with Task and Process, but it seems too low-level for
such a trivial problem.
Could somebody help me to connect the dots please?

Vadym.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Jones
2017-11-22 13:08:06 UTC
Permalink
I don't think you need to worry about explicitly being parallel. Http
requests will be parallel by default due to their async nature in the
Javascript runtime.

You can have your app initialisation return two commands, one for each http
request and then handle their responses separately. You can use Cmd.batch
to group a list of commands into a single command to return as the 'init'
signature needs to only have a single command.

Does that help?
Michael
Post by Vadym Chekan
Hi all,
My app needs to get data from 2 sources upon initialization. Those two
data sources are independent and can be queried in parallel. How do I do it?
I tried to use RemoteData.map2, but it consumes RemoteData structures and
I do not know how to produce it because sendQuery produces command and most
of the functions produce commands and not RemoteData.
I perhaps can do it with Task and Process, but it seems too low-level for
such a trivial problem.
Could somebody help me to connect the dots please?
Vadym.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Vadym Chekan
2017-11-23 01:23:51 UTC
Permalink
Thanks, it does execute it in parallel. But it is not obvious from API.
Also, it is not intuitive to look for http related solutions in Cmd module.

Vadym.
Post by Michael Jones
I don't think you need to worry about explicitly being parallel. Http
requests will be parallel by default due to their async nature in the
Javascript runtime.
You can have your app initialisation return two commands, one for each
http request and then handle their responses separately. You can use
Cmd.batch to group a list of commands into a single command to return as
the 'init' signature needs to only have a single command.
Does that help?
Michael
Post by Vadym Chekan
Hi all,
My app needs to get data from 2 sources upon initialization. Those two
data sources are independent and can be queried in parallel. How do I do it?
I tried to use RemoteData.map2, but it consumes RemoteData structures and
I do not know how to produce it because sendQuery produces command and most
of the functions produce commands and not RemoteData.
I perhaps can do it with Task and Process, but it seems too low-level for
such a trivial problem.
Could somebody help me to connect the dots please?
Vadym.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Frank Bonetti
2017-11-28 19:52:51 UTC
Permalink
The only way to execute two Tasks in parallel is to use Cmd.batch. You
would think that Task.map2, Task.map3, Task.map4, etc. would execute all
tasks in parallel similar to Promise.all, but it doesn't. From the
Put the results of two tasks together. If either task fails, the whole
thing fails. *It also runs in order so the first task will be completely
finished before the second task starts.*
Hi all,
My app needs to get data from 2 sources upon initialization. Those two
data sources are independent and can be queried in parallel. How do I do it?
I tried to use RemoteData.map2, but it consumes RemoteData structures and
I do not know how to produce it because sendQuery produces command and most
of the functions produce commands and not RemoteData.
I perhaps can do it with Task and Process, but it seems too low-level for
such a trivial problem.
Could somebody help me to connect the dots please?
Vadym.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...