aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/concurrency/stm.lux
blob: 1d2c75baabc1930ecf2d96d1daceeb0fd53f594c (plain)
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
50
51
52
(.using
 [library
  [lux {"-" if loop}
   ["$" documentation {"+" documentation:}]
   [data
    [text {"+" \n}
     ["%" format {"+" format}]]]
   [macro
    ["[0]" template]]]]
 [\\library
  ["[0]" /]])

(documentation: (/.Var it)
  "A mutable cell containing a value, and observers that will be alerted of any change to it.")

(documentation: /.var
  "Creates a new STM var, with a default value."
  [(var value)])

(documentation: /.changes
  "Creates a channel that will receive all changes to the value of the given var."
  [(changes target)])

(documentation: (/.STM it)
  "A computation which updates a transaction and produces a value.")

(documentation: /.update
  "Update a var's value, and return a tuple with the old and the new values."
  [(update function var)])

(documentation: /.commit!
  (format "Commits a transaction and returns its result (asynchronously)."
          \n "Note that a transaction may be re-run an indeterminate number of times if other transactions involving the same variables successfully commit first."
          \n "For this reason, it's important to note that transactions must be free from side-effects, such as I/O.")
  [(commit! procedure)])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Var
             ..var
             ..changes
             ..STM
             ..update
             ..commit!
             ($.default /.read)
             ($.default /.write)
             ($.default /.functor)
             ($.default /.apply)
             ($.default /.monad)]
            []))