It sounds like you might actually want to do this in update! You're going 
to have to write an Msg for getting new album covers anyway, right? And, 
conceptually, it sounds like you want to save the results you get but cache 
them for future use through a port.

Your logic branches there, so it makes sense to say, in response to your 
Msg, "save these to display to the user. Also, store them so I don't have 
to make this request again."

If my assumption there is wrong, please correct me. The mechanical way to 
do *exactly *what you're asking is putting your tasks in Task.sequence and 
sending the result through Task.andThen. But I'm not sure you want to do 
that, for the reasons above. Your task handling logic would get really 
hairy, when it has a natural fit in the Elm Architecture.

On Friday, December 1, 2017 at 7:28:08 AM UTC-6, Rafał Cieślak wrote:
>
> I have a dict which acts as an album cover cache:
>
> 1. I download a list of albums from Last.fm.
> 2. I send a separate request for each album to get its cover image URL 
> (right now i use Cmd.batch).
> 2.1 After I receive an image URL from Last.fm, I add it to the cache, so 
> that I have a mapping from album ID to album image URL.
> 3. Once all the album image URL requests finish (no matter if any of them 
> fails), I'd like to send the cache through a port so that JS can save it in 
> localStorage.
>
> I don't know how to approach this. The Cmd API allows for batching, but 
> not sequencing and the Task API allows for sequencing, but not batching. I 
> can turn a Task into Cmd, but not the other way around.
>
> So if I have a bunch of batched HTTP requests, I'm not really able to 
> sequence something after they happen, or at least I don't see how I can do 
> this without adding some dirty workarounds to the update function.
>
> Theoretically I could wrap the album image URLs into RemoteData and then 
> after receiving any of them, see if the rest of the album image URLs is 
> finished and if so, send the cache to JS.
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to