aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/concurrency/async.lux
blob: 769a1a770b7d7cf34e8800efb8a35ac6422f979f (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(.module:
  [library
   [lux (#- or and)
    ["$" documentation (#+ documentation:)]
    [data
     [text (#+ \n)
      ["%" format (#+ format)]]]
    [macro
     ["." template]]]]
  [\\library
   ["." /]])

(documentation: (/.Async it)
  "Represents values produced by asynchronous computations (unlike IO, which is synchronous).")

(documentation: (/.Resolver it)
  (format "The function used to give a value to an async."
          \n "Will signal 'true' if the async has been resolved for the 1st time, 'false' otherwise."))

(documentation: /.resolved
  "Produces an async that has already been resolved to the given value."
  [(resolved value)])

(documentation: /.async
  "Creates a fresh async that has not been resolved yet."
  [(async _)])

(documentation: /.value
  "Polls an async for its value.")

(documentation: /.upon!
  "Executes the given function as soon as the async has been resolved."
  [(upon! function async)])

(documentation: /.resolved?
  "Checks whether an async's value has already been resolved.")

(documentation: /.and
  "Combines the results of both asyncs, in-order."
  [(and left right)])

(documentation: /.or
  (format "Yields the results of whichever async gets resolved first."
          \n "You can tell which one was resolved first through pattern-matching.")
  [(or left right)])

(documentation: /.either
  (format "Yields the results of whichever async gets resolved first."
          \n "You cannot tell which one was resolved first.")
  [(either left right)])

(documentation: /.schedule!
  (format "Runs an I/O computation on its own thread (after a specified delay)."
          \n "Returns an async that will eventually host its result.")
  [(schedule! milli_seconds computation)])

(documentation: /.future
  (format "Runs an I/O computation on its own thread."
          \n "Returns an async that will eventually host its result.")
  [(future computation)])

(documentation: /.after
  "Delivers a value after a certain period has passed."
  [(after milli_seconds value)])

(documentation: /.delay
  "An async that will be resolved after the specified amount of milli-seconds."
  [(delay milli_seconds)])

(documentation: /.within
  "Wait for an async to be resolved within the specified amount of milli-seconds."
  [(within milli_seconds async)])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Async
             ..Resolver
             ..resolved
             ..async
             ..value
             ..upon!
             ..resolved?
             ..and
             ..or
             ..either
             ..schedule!
             ..future
             ..after
             ..delay
             ..within
             ($.default /.functor)
             ($.default /.apply)
             ($.default /.monad)]
            []))