Skip to content

Commit 3d16c3c

Browse files
add intellij repl commands
1 parent f0b0237 commit 3d16c3c

File tree

4 files changed

+114
-64
lines changed

4 files changed

+114
-64
lines changed

.idea/repl-commands.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/async/flow/example/before_his_wings_melted.clj

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@
6262
(show/flow-svg asynctopolis/flow {:chans-as-ports true
6363
:with-content false})
6464

65+
;; Are channels part of a process or not?
66+
;; You decide
67+
6568
(show/flow-svg asynctopolis/flow {:chans-as-ports false
6669
:with-content false})
6770

71+
;; Let's dig deeper into the details
6872

6973
(show/proc-table asynctopolis/flow)
7074

@@ -77,25 +81,25 @@
7781

7882
;; Now we’re seeing the wiring: who talks to whom, and through what channels.
7983

80-
;; Flows implement the `Datafy` protocol so we can inspect them as data...
81-
;; Good luck with that, there's a lot of it
82-
83-
^:kind/portal
84-
(datafy/datafy asynctopolis/flow)
85-
86-
8784
;; ## 3. Running the Flow
8885

8986
;; Time to bring our flow to life!
9087
;; Calling `start` activates the processes and returns a map of the important channels for interaction.
9188

89+
(flow/start asynctopolis/flow)
90+
9291
;; We can now **inject values** into specific points in the flow.
9392
;; Think of this like poking the system and watching how it reacts.
9493

9594
;; We send a “poke” signal to the `aggregator` process.
9695

9796
@(flow/inject asynctopolis/flow [:Tallystrix :poke] [true])
9897

98+
;; Flows implement the `Datafy` protocol so we can inspect them as data...
99+
;; Good luck with that, there's a lot of it
100+
101+
(datafy/datafy asynctopolis/flow)
102+
99103
;; We send a stat string that is designed to trigger an alert.
100104

101105
@(flow/inject asynctopolis/flow [:Tallystrix :stat] ["abc1000"])
@@ -104,6 +108,12 @@
104108

105109
@(flow/inject asynctopolis/flow [:Claxxus :in] [:sandwich])
106110

111+
;; TODO: show something changed
112+
113+
(show/flow-svg asynctopolis/flow {:chans-as-ports false
114+
:with-content false})
115+
116+
107117
;; ## 4. Observing the Results
108118

109119
;; Our flow includes a `report-chan`, where summaries and reports might be sent.
@@ -133,6 +143,21 @@
133143
;; @(flow/inject stats-flow [:aggregator :poke] [true])
134144

135145

146+
147+
; ## Flow
148+
149+
; At its core, flow is a library for building concurrent, event-driven systems
150+
; using simple, communication-free functions.
151+
; It lets you wire up processes and connect them through channels,
152+
; while keeping control, error handling, and monitoring centralized and declarative.
153+
;
154+
;You define the structure as a directed graph—processes,
155+
; their inputs and outputs, and how they connect—and the flow system takes care of orchestration.
156+
; Your logic remains focused, while flow handles execution, coordination, and lifecycle concerns.
157+
;
158+
;All processes can be inspected or observed, and flows are fully data-driven, making them easy to reason about and visualize.
159+
; It's concurrent programming with structure—without the chaos.
160+
136161
; ## Summary
137162

138163
;; By constructing, inspecting, and interacting with a flow, we can understand the

src/core/async/flow/example/flow_show.clj

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -53,67 +53,73 @@
5353
[:div (for [[k v] outs]
5454
[:div [:strong (name k)] ": " v])]]))}))
5555

56-
(defn elkg [flow {:keys [show-chans chans-as-ports with-content]
56+
(defn elkg [flow {:keys [show-chans chans-as-ports with-content proc-width proc-height chan-width chan-height]
5757
:or {show-chans true
5858
chans-as-ports true
59-
with-content false}}]
60-
(let [{:keys [conns procs]} (datafy/datafy flow)
61-
all-proc-chans (into #{} cat conns)]
59+
with-content false
60+
proc-width 60
61+
proc-height 30
62+
chan-width 30
63+
chan-height 12}}]
64+
(let [{:keys [conns procs chans]} (datafy/datafy flow)
65+
{:keys [ins outs error report]} chans
66+
all-proc-chans (into #{} cat conns)
67+
global-chans [{:id "report"
68+
:width chan-width
69+
:height chan-height
70+
:labels [{:text (str "report" "(" (-> report :buffer :count) ")")}]}
71+
{:id "error"
72+
:width chan-width
73+
:height chan-height
74+
:labels [{:text (str "error" "(" (-> error :buffer :count) ")")}]}]
75+
proc-nodes (for [[proc-key proc-chans] (group-by first all-proc-chans)]
76+
(let [{:keys [args proc]} (get procs proc-key)
77+
{:keys [desc]} proc
78+
{:keys [params]} desc
79+
content (when with-content
80+
[{:id (str (name proc-key) "_content")
81+
:width (- proc-width 5)
82+
:height (- proc-height 5)
83+
;; nope, do it by id
84+
:layoutOptions {:content (str/join \newline
85+
(for [[k param] params]
86+
(str (name k) " (" (get args k) ") " param)))}}])
87+
chans (for [[_ chan-k :as proc-chan] proc-chans
88+
:let [chan-name (name chan-k)
89+
{:keys [buffer]} (or (get outs chan-k)
90+
(get ins chan-k))]]
91+
{:id (id-for proc-chan)
92+
:width chan-width
93+
:height chan-height
94+
:labels [{:text (str chan-name " (" (:count buffer) ")")}]})]
95+
{:id (id-for proc-key)
96+
:width proc-width
97+
:height proc-height
98+
:layoutOptions {:org.eclipse.elk.nodeLabels.placement "OUTSIDE V_TOP H_LEFT"}
99+
:labels [{:text (name proc-key)}]
100+
:children (vec (concat content
101+
(when (and show-chans (not chans-as-ports))
102+
chans)))
103+
104+
:ports
105+
(vec (when (and show-chans chans-as-ports)
106+
chans))}))]
62107
{:id "G"
63108
:layoutOptions {:elk.algorithm "layered"
64109
:elk.direction "RIGHT"
65110
:elk.hierarchyHandling "INCLUDE_CHILDREN"}
66-
:children
67-
(for [[proc-key proc-chans] (group-by first all-proc-chans)]
68-
(let [{:keys [args proc]} (get procs proc-key)
69-
{:keys [desc]} proc
70-
{:keys [params ins outs]} desc
71-
width 60
72-
height 30
73-
port-width 20
74-
port-height 12
75-
content (when with-content
76-
[{:id (str (name proc-key) "_content")
77-
:width (- width 5)
78-
:height (- height 5)
79-
;; nope, do it by id
80-
:layoutOptions {:content (str/join \newline
81-
(for [[k param] params]
82-
(str (name k) " (" (get args k) ") " param)))}}])
83-
children (when show-chans
84-
(for [[_ chan :as proc-chan] proc-chans]
85-
{:id (id-for proc-chan)
86-
:width port-width
87-
:height port-height
88-
:labels [{:text (name chan)}]
89-
:children (if with-content
90-
[{:id (str (id-for proc-chan) "_content")
91-
:width port-width
92-
:height port-height
93-
;; nope, do it by id
94-
:layoutOptions {:content (str (name chan)
95-
\newline \newline
96-
(or (get outs chan)
97-
(get ins chan)))}}]
98-
[])}))]
99-
{:id (id-for proc-key)
100-
:width width
101-
:height height
102-
:layoutOptions {:org.eclipse.elk.nodeLabels.placement "OUTSIDE V_TOP H_LEFT"}
103-
:labels [{:text (name proc-key)}]
104-
:children (vec (concat content
105-
(when (and show-chans (not chans-as-ports))
106-
children)))
107-
108-
:ports
109-
(vec (when (and show-chans chans-as-ports)
110-
children))}))
111+
:children (into proc-nodes global-chans)
111112
:edges
112113
(vec (if show-chans
113-
(for [[from to] conns]
114-
{:id (id-for [from to])
115-
:sources [(id-for from)]
116-
:targets [(id-for to)]})
114+
(concat
115+
(for [[from to] conns]
116+
{:id (id-for [from to])
117+
:sources [(id-for from)]
118+
:targets [(id-for to)]})
119+
(for [[p] procs, c ["report" "error"]]
120+
{:id (id-for [p c])
121+
:sources [(id-for p)]
122+
:targets [c]}))
117123
(for [[[from] [to]] conns]
118124
{:id (id-for [from to])
119125
:sources [(id-for from)]

src/graph/layout/structural.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@
128128
(merge-with merge-replace a b)
129129

130130
(and (sequential? a) (sequential? b))
131-
(let [a-map (pairs a)
132-
b-map (pairs b)
131+
(let [a-map (into {} (pairs a))
132+
b-map (into {} (pairs b))
133133
keys (distinct (concat (keys a-map) (keys b-map)))]
134134
(mapv (fn [k]
135135
(if (contains? b-map k)
@@ -169,8 +169,8 @@
169169
a removals)
170170

171171
(and (sequential? a) (sequential? removals))
172-
(let [a-map (pairs a)
173-
r-map (pairs removals)
172+
(let [a-map (into {} (pairs a))
173+
r-map (into {} (pairs removals))
174174
result (reduce-kv
175175
(fn [m k v]
176176
(if (contains? m k)

0 commit comments

Comments
 (0)