Well, took the better part of the day and of course as soon as I post to
the mailing list I figured it out myself.

requestDocuments : Cmd Msg
requestDocuments =
  let
    task = Time.now `andThen` \time -> (
        httpInvoke documentsDecoder time
"/collections/dashboard-alerts/keys"
          |> Task.map (\r -> (r, time))
          |> Task.mapError (\e -> (e, time))
      )
  in
    Task.perform Failed Success task

On Fri, Sep 2, 2016 at 3:12 PM, Bryan Murphy <[email protected]> wrote:

> I'm struggling to compose two tasks.  Specifically, I'm making an HTTP
> request, but I also want to know the time the http request was executed.
>
> I have the following code:
>
> type Msg =
>     Refresh
>   | Success Time Documents
>   | Failed Time Http.Error
>
> requestDocuments : Cmd Msg
> requestDocuments =
>   Task.perform (Failed 0) (Success 0) <| httpInvoke documentsDecoder
> "/collections/dashboard-alerts/keys"
>
> httpInvoke : JsonDecode.Decoder value -> String -> Task.Task Http.Error
> value
> httpInvoke decoder path =
>   let
>     request = {
>       verb = "GET",
>       headers = [ ("Authorization", "Basic SNIP") ],
>       url = ("https://SNIP/1"; ++ path),
>       body = Http.empty
>     }
>   in
>     Http.fromJson decoder <| Http.send Http.defaultSettings request
>
> You can see I'm trying generate the Success/Failed messages that both
> should include a time but for the moment I'm simply injecting a value of
> zero.
>
> It seems like I should use Task.andThen or Task.map or something similar
> to compose httpInvoke with Time.now, but I'm really struggling to pull
> this together and tie it into Task.perform.
>
> Could somebody help?
>
> Thanks!
> Bryan
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to