The old Task.perform was creating either a success message (if it
succeeded) or a fail message (if it failed)
The current Task.perform cannot fail. It is used for Tasks that are known
to succeed like requesting the window size or requesting some random
number.

The Task.attempt takes a function that takes a result (results encapsulate
both the success and the failure) and produces a message based on that
result.

You could define something like:

handleRequest result =
    case result of
        Ok val ->
            SuccessMessage val
        Err err ->
            FailMessage err

and use it like this:

someHttpCmd = Task.attempt handleRequest someHttpRequestTask

Alternatively, you could just have only one message that takes a Result and
handle each case in that message's part of the update as demonstrated by
the Http example:
http://elm-lang.org/examples/http




On Wed, Nov 16, 2016 at 3:05 PM, Tim Bezhashvyly <[email protected]>
wrote:

> Sorry again if something obvious but Im not sure how now to make async
> requests in 0.18.0.
>
> In 0.17.1 it was done with Task.perform where first parameter was a
> success Msg, second - fail Msg and third is the task which execution result
> is then passed to first function.
>
> As far as I understand now Task.attempt must be used but documentation is
> not quite comprehensive. Could someone please advise?
>
> --
> 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.
>



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
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