aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/concurrency/atom.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/concurrency/atom.lux134
1 files changed, 67 insertions, 67 deletions
diff --git a/stdlib/source/lux/control/concurrency/atom.lux b/stdlib/source/lux/control/concurrency/atom.lux
index d15ccfc28..6abe4e756 100644
--- a/stdlib/source/lux/control/concurrency/atom.lux
+++ b/stdlib/source/lux/control/concurrency/atom.lux
@@ -13,73 +13,73 @@
[type
abstract]])
-(`` (for {(~~ (static @.old))
- (host.import: #long (java/util/concurrent/atomic/AtomicReference a)
- (new [a])
- (get [] a)
- (compareAndSet [a a] boolean))
-
- (~~ (static @.jvm))
- (host.import: #long (java/util/concurrent/atomic/AtomicReference a)
- (new [a])
- (get [] a)
- (compareAndSet [a a] boolean))}
- (as-is)))
-
-(`` (abstract: #export (Atom a)
- {#.doc "Atomic references that are safe to mutate concurrently."}
-
- (for {(~~ (static @.old))
- (java/util/concurrent/atomic/AtomicReference a)
-
- (~~ (static @.jvm))
- (java/util/concurrent/atomic/AtomicReference a)
-
- (~~ (static @.js))
- (array.Array a)
- })
-
- (def: #export (atom value)
- (All [a] (-> a (Atom a)))
- (:abstraction (for {(~~ (static @.old))
- (java/util/concurrent/atomic/AtomicReference::new value)
-
- (~~ (static @.jvm))
- (java/util/concurrent/atomic/AtomicReference::new value)
-
- (~~ (static @.js))
- ("js array write" 0 value ("js array new" 1))
- })))
-
- (def: #export (read atom)
- (All [a] (-> (Atom a) (IO a)))
- (io (for {(~~ (static @.old))
- (java/util/concurrent/atomic/AtomicReference::get (:representation atom))
-
- (~~ (static @.jvm))
- (java/util/concurrent/atomic/AtomicReference::get (:representation atom))
-
- (~~ (static @.js))
- ("js array read" 0 (:representation atom))
- })))
-
- (def: #export (compare-and-swap current new atom)
- {#.doc (doc "Only mutates an atom if you can present its current value."
- "That guarantees that atom was not updated since you last read from it.")}
- (All [a] (-> a a (Atom a) (IO Bit)))
- (io (for {(~~ (static @.old))
- (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom))
-
- (~~ (static @.jvm))
- (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom))
-
- (~~ (static @.js))
- (let [old ("js array read" 0 (:representation atom))]
- (if (is? old current)
- (exec ("js array write" 0 new (:representation atom))
- true)
- false))})))
- ))
+(for {@.old
+ (host.import: #long (java/util/concurrent/atomic/AtomicReference a)
+ (new [a])
+ (get [] a)
+ (compareAndSet [a a] boolean))
+
+ @.jvm
+ (host.import: #long (java/util/concurrent/atomic/AtomicReference a)
+ (new [a])
+ (get [] a)
+ (compareAndSet [a a] boolean))}
+ (as-is))
+
+(abstract: #export (Atom a)
+ {#.doc "Atomic references that are safe to mutate concurrently."}
+
+ (for {@.old
+ (java/util/concurrent/atomic/AtomicReference a)
+
+ @.jvm
+ (java/util/concurrent/atomic/AtomicReference a)
+
+ @.js
+ (array.Array a)
+ })
+
+ (def: #export (atom value)
+ (All [a] (-> a (Atom a)))
+ (:abstraction (for {@.old
+ (java/util/concurrent/atomic/AtomicReference::new value)
+
+ @.jvm
+ (java/util/concurrent/atomic/AtomicReference::new value)
+
+ @.js
+ ("js array write" 0 value ("js array new" 1))
+ })))
+
+ (def: #export (read atom)
+ (All [a] (-> (Atom a) (IO a)))
+ (io (for {@.old
+ (java/util/concurrent/atomic/AtomicReference::get (:representation atom))
+
+ @.jvm
+ (java/util/concurrent/atomic/AtomicReference::get (:representation atom))
+
+ @.js
+ ("js array read" 0 (:representation atom))
+ })))
+
+ (def: #export (compare-and-swap current new atom)
+ {#.doc (doc "Only mutates an atom if you can present its current value."
+ "That guarantees that atom was not updated since you last read from it.")}
+ (All [a] (-> a a (Atom a) (IO Bit)))
+ (io (for {@.old
+ (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom))
+
+ @.jvm
+ (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom))
+
+ @.js
+ (let [old ("js array read" 0 (:representation atom))]
+ (if (is? old current)
+ (exec ("js array write" 0 new (:representation atom))
+ true)
+ false))})))
+ )
(def: #export (update f atom)
{#.doc (doc "Updates an atom by applying a function to its current value."