16 | ||| A fiber is a series of computations that will be run
17 | ||| in strict sequence and will eventually terminate
18 | ||| with a result of type `Outcome es a`: It will either
19 | ||| produce a result of type `a`, an error of type `HSum es`,
20 | ||| or - in case it was canceled early - end with `Canceled`.
21 | |||
22 | ||| From the outside, a fiber can be observed by installing
23 | ||| a callback, which will be invoked as soon as the fiber has
24 | ||| terminated with a result.
25 | |||
26 | ||| In addition, a running fiber can be canceled, so that it
27 | ||| aborts all computations at soon as possible. Canceling a fiber
28 | ||| that has already completed is a no-op.
35 | ||| Sum-type describing the computation running on a fiber.
36 | |||
37 | ||| `Async` can be thought of a powerful alternative to `IO`
38 | ||| that comes with error handling, capabilities for
39 | ||| spawning additional `Async` computations (each running
40 | ||| on its of `Fiber`), plus the ability for being canceled
41 | ||| (from the inside or from other fibers).
42 | |||
43 | ||| In order to *run* an `Async` computation, we an
44 | ||| `IO.Async.Loop.EventLoop`, which takes care of running
45 | ||| many fibers (each of which might spawn additional fibers)
46 | ||| concurrently. Some event loops will even offer true parallelism,
47 | ||| distributing the fibers to be run across several operating
48 | ||| system threads.
51 | ||| Implements bind (`>>=`)
54 | ||| A pure result
57 | ||| An error
60 | ||| A wrapped synchronous/blocking IO action
63 | ||| Cancels the curret fiber
66 | ||| Run the given cancel hook when cancelation is observed for `act`
69 | ||| Masks a fiber as uncanceble
70 | ||| This takes a function argument which will get the running fiber's
71 | ||| identifier token plus cancelation id in order to unmask certain
72 | ||| inner regions, where cancellation can again be observed.
73 | ||| See also `Poll`.
76 | ||| Error handling: In case an error occured, it is wrapped in
77 | ||| a `Left`, while a successful result is wrapped in a `Right`.
78 | ||| Note, that we do not handle the `Canceled` case: Cancellation
79 | ||| cannot be undone. In can be temporarily masked using `UC`, but
80 | ||| after that, it will be observed as soon as possible.
83 | ||| Returns the context currently handling this fiber, giving us access
84 | ||| to functionality specific to the running event loop.
87 | ||| Returns the current fiber's unique identifier
90 | ||| Cedes control to the execution context
91 | ||| Fibers are auto-ceded after a predefined number of evaluation steps
92 | ||| to make sure other fibers get a chance to run even when the event loop
93 | ||| is single-threaded. In addition, a fiber can make room for other
94 | ||| fibers by invoking `cede` at strategic points.
97 | ||| Runs the given computation concurrently to this one returning a
98 | ||| `Fiber` representing the runnign computation.
101 | ||| The asynchronous primitive. This allows us to register callbacks
102 | ||| and await their invocation, thus blocking the current fiber until
103 | ||| a result is ready. Being able to treat this as a regular
104 | ||| IO-like computation is one of the main reasons why `Async` is such
105 | ||| a powerful abstraction.
106 | |||
107 | ||| The `IO1 ()` returned after installing a callback will be treated
108 | ||| as a cancellation hook: It will be invoked if the current
109 | ||| computation is canceled and cancellation can currently be observed.
110 | |||
111 | ||| We use this data constructor whenever we'd like to wait for a
112 | ||| result to be ready at a later time such as a timer, input from
113 | ||| a pipe or socket, or data available from standard input.
116 | ||| Temporarily undo a layer of uncancelability. See also `UC`.
119 | --------------------------------------------------------------------------------
120 | -- Primitives
121 | --------------------------------------------------------------------------------
123 | ||| Lifts a pure `Result` into `Async`.
128 | ||| Lifts an effectful `Result` into `Async`.
133 | ||| Asynchronous FFI: Wraps a callback handler into `Async`.
134 | |||
135 | ||| The `IO1 ()` action returned after registering the callback will
136 | ||| be used for cancelation and cleanup.
141 | ||| Starts a new fiber, running it concurrently to the current one
146 | ||| Cedes control back to the execution context.
151 | ||| Returns the environment provided by the event loop this
152 | ||| fiber is currently running in.
157 | ||| Returns this fiber's unique identifier.
162 | --------------------------------------------------------------------------------
163 | -- Interfaces
164 | --------------------------------------------------------------------------------