Skip to content

Commit 17b0538

Browse files
committed
:inject in process fn-map is now :introduce, more accurate and avoids confusion with flow/inject
1 parent 3ee4a34 commit 17b0538

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/main/clojure/clojure/core/async/flow.clj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
8484
::flow/report-chan - a core.async chan for reading.'ping' reponses
8585
will show up here, as will any explicit ::flow/report outputs
86-
from :transform/:inject
86+
from :transform/:introduce
8787
8888
::flow/error-chan - a core.async chan for reading. Any (and only)
8989
exceptions thrown anywhere on any thread inside a flow will appear
@@ -138,7 +138,7 @@
138138
"Given a map of functions (described below), returns a launcher that
139139
creates a process compliant with the process protocol (see the
140140
spi/ProcLauncher doc). The possible entries for process-impl-map
141-
are :describe, :init, :transition, :transform and :inject. This is
141+
are :describe, :init, :transition, :transform and :introduce. This is
142142
the core facility for defining the logic for processes via ordinary
143143
functions.
144144
@@ -171,7 +171,7 @@
171171
process will no longer be used following that. See the SPI for
172172
details. state' will be the state supplied to subsequent calls.
173173
174-
Exactly one of either :transform or :inject are required.
174+
Exactly one of either :transform or :introduce are required.
175175
176176
:transform - (state in-name msg) -> [state' output]
177177
where output is a map of outid->[msgs*]
@@ -184,19 +184,19 @@
184184
may never be nil (per core.async channels). state' will be the state
185185
supplied to subsequent calls.
186186
187-
:inject - (state) -> [state' output]
187+
:introduce - (state) -> [state' output]
188188
where output is a map of outid->[msgs*], per :transform
189189
190-
The inject fn is used for sources - proc-impls that inject new data
190+
The introduce fn is used for sources - proc-impls that introduce new data
191191
into the flow by doing I/O with something external to the flow and
192-
feeding that data to its outputs. A proc-impl specifying :inject may not
192+
feeding that data to its outputs. A proc-impl specifying :introduce may not
193193
specify any :ins in its descriptor, as none but the ::flow/control channel
194-
will be read. Instead, inject will be called every time through the
194+
will be read. Instead, introduce will be called every time through the
195195
process loop, and will presumably do blocking or paced I/O to get
196196
new data to return via its outputs. If it does blocking I/O it
197197
should do so with a timeout so it can regularly return to the
198198
process loop which can then look for control messages - it's fine
199-
for inject to return with no output. Do not spin poll in the inject
199+
for introduce to return with no output. Do not spin poll in the introduce
200200
fn.
201201
202202
proc accepts an option map with keys:
@@ -205,13 +205,13 @@
205205
will be used when getting the return from the future - see below
206206
207207
The :compute context is not allowed for proc impls that
208-
provide :inject (as I/O is presumed).
208+
provide :introduce (as I/O is presumed).
209209
210210
In the :exec context of :mixed or :io, this dictates the type of
211211
thread in which the process loop will run, _including its calls to
212-
transform/inject_.
212+
transform/introduce_.
213213
214-
When :io is specified transform/inject should not do extensive computation.
214+
When :io is specified transform/introduce should not do extensive computation.
215215
216216
When :compute is specified (only allowed for :transform), each call
217217
to transform will be run in a separate thread. The process loop will

src/main/clojure/clojure/core/async/flow/impl.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
(loop [nstatus nstatus, nstate nstate, msgs (seq msgs)]
203203
(if (or (nil? msgs) (= nstatus :exit))
204204
[nstatus nstate]
205-
(let [m (if-some [m (first msgs)] m (throw "messages must be non-nil"))
205+
(let [m (if-some [m (first msgs)] m (throw (Exception. "messages must be non-nil")))
206206
[v c] (async/alts!!
207207
[control [outc m]]
208208
:priority true)]
@@ -216,10 +216,10 @@
216216

217217
(defn proc
218218
"see lib ns for docs"
219-
[{:keys [describe init transition transform inject] :as impl} {:keys [exec compute-timeout-ms]}]
219+
[{:keys [describe init transition transform introduce] :as impl} {:keys [exec compute-timeout-ms]}]
220220
;;validate the preconditions
221-
(assert (= 1 (count (keep identity [transform inject]))) "must provide exactly one of :transform or :inject")
222-
(assert (not (and inject (= exec :compute))) "can't specify :inject and :compute")
221+
(assert (= 1 (count (keep identity [transform introduce]))) "must provide exactly one of :transform or :introduce")
222+
(assert (not (and introduce (= exec :compute))) "can't specify :introduce and :compute")
223223
(reify
224224
clojure.core.protocols/Datafiable
225225
(datafy [_]
@@ -228,7 +228,7 @@
228228
spi/ProcLauncher
229229
(describe [_]
230230
(let [{:keys [params ins] :as desc} (describe)]
231-
(assert (not (and ins inject)) "can't specify :ins when :inject")
231+
(assert (not (and ins introduce)) "can't specify :ins when :introduce")
232232
(assert (or (not params) init) "must have :init if :params")
233233
desc))
234234
(start [_ {:keys [pid args ins outs resolver]}]
@@ -261,7 +261,7 @@
261261
;;:running
262262
(let [[msg c] (if transform
263263
(async/alts!! read-chans :priority true)
264-
;;inject
264+
;;introduce
265265
(when-let [msg (async/poll! control)]
266266
[msg control]))
267267
cid (io-id c)]
@@ -272,7 +272,7 @@
272272
(try
273273
(let [[nstate outputs] (if transform
274274
(transform state cid msg)
275-
(inject state))
275+
(introduce state))
276276
[nstatus nstate]
277277
(send-outputs status nstate outputs outs resolver control handle-command transition)]
278278
[nstatus nstate (inc count)])

0 commit comments

Comments
 (0)