惯用的 clojure:从一个频道中取出多个项目

Idiomatic clojure: taking multiple items off a channel

我有一个通道,我在其中输入了一些单独的值(顺便说一下,JSON 行)。

在从通道中取出值时,我希望将它们作为一个整体进行批处理。频道中是否有任何 take n 的概念,或者是否有将它们捆绑成 vector/sequence/list 的方法?

您可以使用 clojure.core.async/take to take a specific number of items off a channel. They are returned in the form of a new channel, so you still have to use <!, <!!, or take! to process them individually. If you want to process them as a group, you can use clojure.core.async/into 将它们放入标准的 Clojure 数据结构中。