forked from andrewMacmurray/elm-concurrent-task
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcurrentTask.elm
More file actions
49 lines (38 loc) · 1.1 KB
/
ConcurrentTask.elm
File metadata and controls
49 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
port module Spa.ConcurrentTask exposing (attempt, progress, subscriptions)
import ConcurrentTask exposing (ConcurrentTask)
import Effect
import Json.Decode as Decode
subscriptions :
(( ConcurrentTask.Pool msg, Cmd msg ) -> msg)
-> { model | tasks : ConcurrentTask.Pool msg }
-> Sub msg
subscriptions onProgress { tasks } =
ConcurrentTask.onProgress
{ onProgress = onProgress
, send = send
, receive = receive
}
tasks
progress :
{ model | tasks : pool }
-> ( pool, Cmd msg )
-> ( { model | tasks : pool }, Effect.Effect msg )
progress model ( tasks, cmd ) =
( { model | tasks = tasks }
, Effect.sendCmd cmd
)
attempt :
{ task : ConcurrentTask x a
, pool : ConcurrentTask.Pool msg
, onComplete : ConcurrentTask.Response x a -> msg
}
-> ( ConcurrentTask.Pool msg, Cmd msg )
attempt { task, pool, onComplete } =
ConcurrentTask.attempt
{ send = send
, pool = pool
, onComplete = onComplete
}
task
port send : Decode.Value -> Cmd msg
port receive : (Decode.Value -> msg) -> Sub msg