Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ Your Elm program needs:

```elm
type alias Model =
{ tasks : ConcurrentTask.Pool Msg Error Success
{ tasks : ConcurrentTask.Pool Msg
}
```

- 2 `Msg`s to handle task updates:

```elm
type Msg
= OnProgress ( ConcurrentTask.Pool Msg Error Success, Cmd Msg ) -- updates task progress
= OnProgress ( ConcurrentTask.Pool Msg, Cmd Msg ) -- updates task progress
| OnComplete (ConcurrentTask.Response Error Success) -- called when a task completes
```

Expand All @@ -236,12 +236,12 @@ import Json.Decode as Decode


type alias Model =
{ tasks : ConcurrentTask.Pool Msg Error Titles
{ tasks : ConcurrentTask.Pool Msg
}


type Msg
= OnProgress ( ConcurrentTask.Pool Msg Error Titles, Cmd Msg )
= OnProgress ( ConcurrentTask.Pool Msg, Cmd Msg )
| OnComplete (ConcurrentTask.Response Error Titles)


Expand Down
2 changes: 1 addition & 1 deletion examples/dom-operations/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type alias Flags =


type alias Pool =
ConcurrentTask.Pool Msg Error Output
ConcurrentTask.Pool Msg


type alias Error =
Expand Down
2 changes: 1 addition & 1 deletion examples/fruits-pipeline-worker/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Msg


type alias Pool =
Task.Pool Msg Error Output
Task.Pool Msg


type Error
Expand Down
2 changes: 1 addition & 1 deletion examples/localstorage-fruit-trees/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ updatePears n fruits =


type alias Pool =
ConcurrentTask.Pool Msg Error Output
ConcurrentTask.Pool Msg


type alias Error =
Expand Down
4 changes: 2 additions & 2 deletions examples/many-requests/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ port module Main exposing (main)
import ConcurrentTask as Task exposing (ConcurrentTask)
import ConcurrentTask.Http as Http
import ConcurrentTask.Process
import Json.Decode as Decode exposing (Decoder)
import Json.Decode as Decode


{-| Many Requests
Expand Down Expand Up @@ -37,7 +37,7 @@ type Msg


type alias Pool =
Task.Pool Msg Error Output
Task.Pool Msg


type alias Error =
Expand Down
2 changes: 1 addition & 1 deletion examples/spa-example/src/Pages/Home_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ getTodo id =


type alias Pool =
ConcurrentTask.Pool Msg Error Output
ConcurrentTask.Pool Msg


type alias Error =
Expand Down
2 changes: 1 addition & 1 deletion examples/spa-example/src/Pages/Posts.elm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ getPost id =


type alias Pool =
ConcurrentTask.Pool Msg Error Output
ConcurrentTask.Pool Msg


type alias Error =
Expand Down
8 changes: 4 additions & 4 deletions examples/spa-example/src/Spa/ConcurrentTask.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Json.Decode as Decode


subscriptions :
(( ConcurrentTask.Pool msg x a, Cmd msg ) -> msg)
-> { model | tasks : ConcurrentTask.Pool msg x a }
(( ConcurrentTask.Pool msg, Cmd msg ) -> msg)
-> { model | tasks : ConcurrentTask.Pool msg }
-> Sub msg
subscriptions onProgress { tasks } =
ConcurrentTask.onProgress
Expand All @@ -30,10 +30,10 @@ progress model ( tasks, cmd ) =

attempt :
{ task : ConcurrentTask x a
, pool : ConcurrentTask.Pool msg x a
, pool : ConcurrentTask.Pool msg
, onComplete : ConcurrentTask.Response x a -> msg
}
-> ( ConcurrentTask.Pool msg x a, Cmd msg )
-> ( ConcurrentTask.Pool msg, Cmd msg )
attempt { task, pool, onComplete } =
ConcurrentTask.attempt
{ send = send
Expand Down
2 changes: 1 addition & 1 deletion integration/src/Integration/Runner.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Msg


type alias Pool =
Task.Pool Msg Error Output
Task.Pool Msg


type alias Error =
Expand Down
63 changes: 37 additions & 26 deletions src/ConcurrentTask.elm
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ Here's a minimal complete example:
import Json.Decode as Decode

type alias Model =
{ tasks : ConcurrentTask.Pool Msg Http.Error Titles
{ tasks : ConcurrentTask.Pool Msg
}

type Msg
= OnProgress ( ConcurrentTask.Pool Msg Http.Error Titles, Cmd Msg )
= OnProgress ( ConcurrentTask.Pool Msg, Cmd Msg )
| OnComplete (ConcurrentTask.Response Http.Error Titles)

init : ( Model, Cmd Msg )
Expand Down Expand Up @@ -882,18 +882,42 @@ Make sure to update your `Model` and pass in the `Cmd` returned from `attempt`.

-}
attempt :
{ pool : Pool msg x a
{ pool : Pool msg
, send : Decode.Value -> Cmd msg
, onComplete : Response x a -> msg
}
-> ConcurrentTask x a
-> ( Pool msg x a, Cmd msg )
attempt options =
-> ( Pool msg, Cmd msg )
attempt config task =
let
mappedTask : ConcurrentTask msg msg
mappedTask =
task
|> map (\res -> config.onComplete (Success res))
|> onError
(\err ->
config.onComplete (Error err)
|> succeed
)

onComplete : Internal.Response msg msg -> msg
onComplete res =
case res of
Internal.Success s ->
s

Internal.Error e ->
e

Internal.UnexpectedError e ->
config.onComplete (UnexpectedError (toUnexpectedError e))
in
Internal.attempt
{ pool = options.pool
, send = options.send
, onComplete = toResponse >> options.onComplete
{ pool = config.pool
, send = config.send
, onComplete = onComplete
}
mappedTask


{-| The value returned from a task when it completes (returned in the `OnComplete` msg).
Expand Down Expand Up @@ -939,19 +963,6 @@ type UnexpectedError
| InternalError String


toResponse : Internal.Response x a -> Response x a
toResponse res =
case res of
Internal.Success a ->
Success a

Internal.Error x ->
Error x

Internal.UnexpectedError e ->
UnexpectedError (toUnexpectedError e)


toUnexpectedError : Internal.UnexpectedError -> UnexpectedError
toUnexpectedError err =
case err of
Expand Down Expand Up @@ -1000,9 +1011,9 @@ Make sure to update your `Model` and pass in the `Cmd` in your `OnProgress` bran
onProgress :
{ send : Decode.Value -> Cmd msg
, receive : (Decode.Value -> msg) -> Sub msg
, onProgress : ( Pool msg x a, Cmd msg ) -> msg
, onProgress : ( Pool msg, Cmd msg ) -> msg
}
-> Pool msg x a
-> Pool msg
-> Sub msg
onProgress =
Internal.onProgress
Expand All @@ -1011,8 +1022,8 @@ onProgress =
{-| A Pool keeps track of each task's progress,
and allows multiple Task attempts to be in-flight at the same time.
-}
type alias Pool msg x a =
Internal.Pool msg x a
type alias Pool msg =
Internal.Pool msg


{-| Create an empty ConcurrentTask Pool.
Expand All @@ -1024,6 +1035,6 @@ Right now it doesn't expose any functionality, but it could be used in the futur
- Expose metrics on previous or running tasks.

-}
pool : Pool msg x a
pool : Pool msg
pool =
Internal.pool
Loading