aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/concurrency/task.lux
diff options
context:
space:
mode:
authorEduardo Julian2017-06-24 23:58:46 -0400
committerEduardo Julian2017-06-24 23:58:46 -0400
commitfed9d0eb94a8808fe119f39fddf882754cd58788 (patch)
treee4ae053453913c63b80f2fe2b120b67405df42bb /stdlib/source/lux/concurrency/task.lux
parent6b04fc4a718b7eb40e72fdb02a8fa4f7cf4ea64a (diff)
- Re-designed actors so that their messages are now functions with access to the actor's state, and to the actor itself.
- When creating channels and promises, the type is now mandatory. - Minor refactorings.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/concurrency/task.lux26
1 files changed, 23 insertions, 3 deletions
diff --git a/stdlib/source/lux/concurrency/task.lux b/stdlib/source/lux/concurrency/task.lux
index 239572bff..f46d1f0da 100644
--- a/stdlib/source/lux/concurrency/task.lux
+++ b/stdlib/source/lux/concurrency/task.lux
@@ -3,13 +3,28 @@
(lux (data ["R" result])
(control functor
applicative
- monad)
+ monad
+ ["ex" exception #+ Exception])
(concurrency ["P" promise])
+ [macro]
+ (macro ["s" syntax #+ syntax: Syntax])
))
(type: #export (Task a)
(P;Promise (R;Result a)))
+(def: #export (fail error)
+ (All [a] (-> Text (Task a)))
+ (:: P;Applicative<Promise> wrap (#R;Error error)))
+
+(def: #export (throw exception message)
+ (All [a] (-> Exception Text (Task a)))
+ (fail (exception message)))
+
+(def: #export (return value)
+ (All [a] (-> a (Task a)))
+ (:: P;Applicative<Promise> wrap (#R;Success value)))
+
(struct: #export _ (Functor Task)
(def: (map f fa)
(:: P;Functor<Promise> map
@@ -25,8 +40,7 @@
(struct: #export _ (Applicative Task)
(def: functor Functor<Task>)
- (def: (wrap a)
- (:: P;Applicative<Promise> wrap (#R;Success a)))
+ (def: wrap return)
(def: (apply ff fa)
(do P;Monad<Promise>
@@ -49,3 +63,9 @@
(#R;Success ma)
ma))))
+
+(syntax: #export (task [type s;any])
+ {#;doc (doc "Makes an uninitialized Task (in this example, of Unit)."
+ (task Unit))}
+ (wrap (list (` (: (;;Task (~ type))
+ (P;promise' #;None))))))