(我有一个上一个问题here,并假设我没有遇到问题转到core.async)。
给出如下输入数据:
<input style="color:black" type="text" name="id" value="<?= $id ?? '' ?>" placeholder="10001">
<input style="color:black;" type="text" value="<?= array_key_exists('newAddress', $_POST) ? $_POST['newAddress'] : '' ?>" name="newAddress" placeholder="New Address">
...
(require '[clojure.core.async :as a])
(def input-data
[{:itm_na 1 :seq_no 1 :doc_img "this is a very long "}
{:itm_na 1 :seq_no 2 :doc_img "sentence from a mainframe "}
{:itm_na 1 :seq_no 3 :doc_img "system that was built before i was "}
{:itm_na 1 :seq_no 4 :doc_img "born."}
{:itm_na 2 :seq_no 1 :doc_img "this is a another very long "}
{:itm_na 2 :seq_no 2 :doc_img "sentence from the same mainframe "}
{:itm_na 3 :seq_no 1 :doc_img "Ok here we are again. "}
{:itm_na 3 :seq_no 2 :doc_img "The mainframe only had 40 char per field so"}
{:itm_na 3 :seq_no 3 :doc_img "they broke it into multiple rows "}
{:itm_na 3 :seq_no 4 :doc_img "which seems to be common"}
{:itm_na 3 :seq_no 5 :doc_img " for the time. "}
{:itm_na 3 :seq_no 6 :doc_img "thanks for your help."}])
(正如预期的那样)将我的数据集中到seq中(以便稍后崩溃):
partition-by
然而,当我因某种原因尝试用(count (partition-by :itm_na input-data ))
;;=> 3
管道执行此操作时
似乎没有做同样的...我如何获得有状态传感器的一部分
core.async
在异步管道中实际保留状态?
partition-by
这应该是3?
奇怪的是,当我将(let
[source-chan (a/to-chan input-data)
target-chan (a/chan 100)
xf (comp (partition-by :itm_na))
]
(a/pipeline 1
target-chan
xf
source-chan)
(count (<!! (a/into [] target-chan))))
;;=>12
绑定到下面的频道时,我得到了预期的结果。我不确定xf
为什么表现不同。
a/pipeline
从文档中......提到有状态位:
(let [xf (comp (partition-by :itm_na))
ch (a/chan 1 xf)]
(a/onto-chan ch input-data)
(count (<!! (a/into [] ch))))
=>3
答案 0 :(得分:2)
这个特例是Rich Hickey在他的演讲中briefly highlighted:你不能将pipeline
与状态传感器一起使用,主要是因为pipeline
的并行性质。