|
13 | 13 | a set of channels for centralized control, reporting, error-handling,
|
14 | 14 | and execution of the processes
|
15 | 15 |
|
| 16 | +The flow library itself constructs processes, channels and flows. The |
| 17 | +user provides configuration data and process logic (step-fns) that |
| 18 | +specify how the flow should work. |
| 19 | + |
16 | 20 | A flow is constructed from flow configuration data which defines a
|
17 | 21 | directed graph of processes and the connections between
|
18 | 22 | them. Processes describe their I/O requirements and the
|
|
22 | 26 | policy decisions regarding process settings, threading, buffering etc.
|
23 | 27 |
|
24 | 28 | It is expected that applications will rarely define instances of the
|
25 |
| -process protocol but instead use the API functions here, 'process' |
26 |
| -and 'step-process', that implement the process protocol in terms of |
27 |
| -calls to ordinary functions that might include no communication or |
| 29 | +process protocol but instead use the API function 'process' that |
| 30 | +implements the process protocol in terms of calls to ordinary |
| 31 | +functions (step-fns) that might include no communication or |
28 | 32 | core.async code. In this way the library helps you achieve a strict
|
29 | 33 | separation of your application logic from its execution,
|
30 | 34 | communication, lifecycle, error handling and monitoring.
|
|
36 | 40 | the library itself as ::flow/xyz, where ::flow is an alias for
|
37 | 41 | clojure.core.async.flow
|
38 | 42 |
|
| 43 | +Flows support the Clojure 'datafy' protocol to support |
| 44 | +observability. See also the 'ping' and 'ping-proc' fns for a live |
| 45 | +view of processes. |
| 46 | + |
39 | 47 | A process is represented in the flow definition by an implementation
|
40 | 48 | of spi/ProcLauncher that starts it. See the spi docs for
|
41 | 49 | details.</pre></div><div class="public anchor" id="var-command-proc"><h3>command-proc</h3><div class="usage"><code>(command-proc g pid cmd-id more-kvs)</code></div><div class="doc"><pre class="plaintext">synchronously sends a process-specific command with the given id and
|
|
73 | 81 | default :mixed</pre></div></div><div class="public anchor" id="var-inject"><h3>inject</h3><div class="usage"><code>(inject g [pid io-id :as coord] msgs)</code></div><div class="doc"><pre class="plaintext">asynchronously puts the messages on the channel corresponding to the
|
74 | 82 | input or output of the process, returning a future that will
|
75 | 83 | complete when done.</pre></div></div><div class="public anchor" id="var-lift*-.3Estep"><h3>lift*->step</h3><div class="usage"><code>(lift*->step f)</code></div><div class="doc"><pre class="plaintext">given a fn f taking one arg and returning a collection of non-nil
|
76 |
| -values, create a 'step' fn as needed by step-process, with one input |
| 84 | +values, creates a step fn as needed by process, with one input |
77 | 85 | and one output (named :in and :out), and no state.</pre></div></div><div class="public anchor" id="var-lift1-.3Estep"><h3>lift1->step</h3><div class="usage"><code>(lift1->step f)</code></div><div class="doc"><pre class="plaintext">like lift*->step except taking a fn returning one value, which when
|
78 | 86 | nil will yield no output.</pre></div></div><div class="public anchor" id="var-pause"><h3>pause</h3><div class="usage"><code>(pause g)</code></div><div class="doc"><pre class="plaintext">pauses a running flow
|
79 | 87 | </pre></div></div><div class="public anchor" id="var-pause-proc"><h3>pause-proc</h3><div class="usage"><code>(pause-proc g pid)</code></div><div class="doc"><pre class="plaintext">pauses a process
|
80 | 88 | </pre></div></div><div class="public anchor" id="var-ping"><h3>ping</h3><div class="usage"><code>(ping g & {:keys [timeout-ms], :or {timeout-ms 1000}})</code></div><div class="doc"><pre class="plaintext">pings all processes, returning a map of pid -> proc status and
|
81 | 89 | state, for those procs that reply within timeout-ms (default 1000)</pre></div></div><div class="public anchor" id="var-ping-proc"><h3>ping-proc</h3><div class="usage"><code>(ping-proc g pid & {:keys [timeout-ms], :or {timeout-ms 1000}})</code></div><div class="doc"><pre class="plaintext">like ping, but just pings the specified process
|
82 |
| -</pre></div></div><div class="public anchor" id="var-process"><h3>process</h3><div class="usage"><code>(process fn-or-map)</code><code>(process fn-or-map {:keys [workload timeout-ms], :or {timeout-ms 5000}, :as opts})</code></div><div class="doc"><pre class="plaintext">Given a function of four arities (0-3), or a map of functions |
83 |
| -corresponding thereto (described below), returns a launcher that |
84 |
| -creates a process compliant with the process protocol (see the |
85 |
| -spi/ProcLauncher doc). |
86 |
| - |
87 |
| -The possible arities/entries for fn/map are 0 - :describe, 1 |
88 |
| -- :init, 2 - :transition and 3 - :transform. This is the core |
89 |
| -facility for defining the logic for processes via ordinary |
90 |
| -functions. Using a var holding a fn as the 'fn' is the preferred |
91 |
| -method for defining a proc, as it enables hot-code-reloading of the |
92 |
| -proc logic in a flow, and better names in datafy. You can use the |
93 |
| -map form to compose the proc logic from disparate functions or to |
94 |
| -leverage the optionality of some of the entry points. |
| 90 | +</pre></div></div><div class="public anchor" id="var-process"><h3>process</h3><div class="usage"><code>(process fn-or-map)</code><code>(process fn-or-map {:keys [workload timeout-ms], :or {timeout-ms 5000}, :as opts})</code></div><div class="doc"><pre class="plaintext">Given a function of four arities (0-3), aka the 'step-fn', or a map |
| 91 | +of functions corresponding thereto (described below), returns a |
| 92 | +launcher that creates a process compliant with the process |
| 93 | +protocol (see the spi/ProcLauncher doc). |
| 94 | + |
| 95 | +The possible arities/entries for the step-fn/map are |
| 96 | + |
| 97 | +0 - :describe, |
| 98 | +1 - :init, |
| 99 | +2 - :transition |
| 100 | +3 - :transform. |
| 101 | + |
| 102 | +This is the core facility for defining the logic for processes via |
| 103 | +ordinary functions. Using a var holding a fn as the 'step-fn' is the |
| 104 | +preferred method for defining a proc, as it enables |
| 105 | +hot-code-reloading of the proc logic in a flow, and better names in |
| 106 | +datafy. You can use the map form to compose the proc logic from |
| 107 | +disparate functions or to leverage the optionality of some of the |
| 108 | +entry points. |
95 | 109 |
|
96 | 110 | arity 0, or :describe - required, () -> description
|
97 | 111 | where description is a map with keys :params :ins and :outs, each of which
|
|
117 | 131 |
|
118 | 132 | init will be called once by the process to establish any initial
|
119 | 133 | state. The arg-map will be a map of param->val, as supplied in the
|
120 |
| -flow def. init must be provided if 'describe' returns :params. |
| 134 | +flow def. The key ::flow/pid will be added, mapped to the pid |
| 135 | +associated with the process (useful e.g. if the process wants to |
| 136 | +refer to itself in reply-to coordinates). init must be provided if |
| 137 | +'describe' returns :params. |
121 | 138 |
|
122 | 139 | Optionally, a returned init state may contain the
|
123 | 140 | keys ::flow/in-ports and/or ::flow/out-ports. These should be maps
|
|
181 | 198 | When :compute is specified transform must not block!</pre></div></div><div class="public anchor" id="var-resume"><h3>resume</h3><div class="usage"><code>(resume g)</code></div><div class="doc"><pre class="plaintext">resumes a paused flow
|
182 | 199 | </pre></div></div><div class="public anchor" id="var-resume-proc"><h3>resume-proc</h3><div class="usage"><code>(resume-proc g pid)</code></div><div class="doc"><pre class="plaintext">resumes a process
|
183 | 200 | </pre></div></div><div class="public anchor" id="var-start"><h3>start</h3><div class="usage"><code>(start g)</code></div><div class="doc"><pre class="plaintext">starts the entire flow from init values. The processes start paused.
|
184 |
| -Call 'resume' or 'resume-proc' to start flow. returns a map with keys: |
| 201 | +Call 'resume' or 'resume-proc' to start flow. Returns a map with keys: |
185 | 202 |
|
186 | 203 | :report-chan - a core.async chan for reading.'ping' reponses
|
187 | 204 | will show up here, as will any explicit ::flow/report outputs
|
|
0 commit comments