You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/ConcurrentTask.elm
+79-10Lines changed: 79 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,8 @@ module ConcurrentTask exposing
9
9
, race
10
10
, batch, sequence
11
11
, map, andMap, map2, map3, map4, map5
12
-
, attempt, attemptEach,Response(..),UnexpectedError(..), onProgress,Pool, pool, withPoolId
12
+
, attempt, attemptWithId, attemptEach,Response(..),UnexpectedError(..), onProgress,Pool, pool, withPoolId
13
+
, cancel, cancelAll
13
14
)
14
15
15
16
{-| A Task similar to `elm/core`'s `Task` but:
@@ -194,7 +195,14 @@ Here's a minimal complete example:
194
195
, subscriptions = subscriptions
195
196
}
196
197
197
-
@docs attempt, attemptEach, Response, UnexpectedError, onProgress, Pool, pool, withPoolId
198
+
@docs attempt, attemptWithId, attemptEach, Response, UnexpectedError, onProgress, Pool, pool, withPoolId
199
+
200
+
201
+
# Cancel Tasks
202
+
203
+
These can be used to stop running tasks from outside the task chain.
204
+
205
+
@docs cancel, cancelAll
198
206
199
207
-}
200
208
@@ -1093,7 +1101,38 @@ attempt :
1093
1101
}
1094
1102
->ConcurrentTask x a
1095
1103
->(Pool msg,Cmd msg )
1096
-
attempt config task =
1104
+
attempt options task =
1105
+
let
1106
+
( _, p, cmd )=
1107
+
attemptWithId options task
1108
+
in
1109
+
( p, cmd )
1110
+
1111
+
1112
+
{-| Start a `ConcurrentTask` identical to [attempt](ConcurrentTask#attempt) except it returns an additional `String` id that can be used to cancel the task.
1113
+
1114
+
Pass this `String` id to [cancel](ConcurrentTask#cancel) to stop the running task. Below is a contrived example but it would stop the task immediately:
1115
+
1116
+
let
1117
+
( id, tasks, cmd ) =
1118
+
ConcurrentTask.attemptWithId
1119
+
{ send = send
1120
+
, pool = model.pool
1121
+
, onComplete = OnComplete
1122
+
}
1123
+
myTask
1124
+
in
1125
+
( { model | tasks = ConcurrentTask.cancel id tasks }, cmd )
0 commit comments