小编Pet*_*ott的帖子

当mapcat在core.async中破坏背压时,内存泄漏在哪里?

我在Clojure中编写了一些core.async代码,当我运行它时,它消耗了所有可用的内存并因错误而失败.似乎mapcat在core.async管道中使用可以打破压力.(由于超出本问题范围的原因,这是不幸的.)

下面是一些通过计算:x输入和输出mapcat换能器来演示问题的代码:

(ns mapcat.core
  (:require [clojure.core.async :as async]))

(defn test-backpressure [n length]
  (let [message (repeat length :x)
        input (async/chan)
        transform (async/chan 1 (mapcat seq))
        output (async/chan)
        sent (atom 0)]
    (async/pipe input transform)
    (async/pipe transform output)
    (async/go
      (dotimes [_ n]
        (async/>! input message)
        (swap! sent inc))
      (async/close! input))
    (async/go-loop [x 0]
      (when (= 0 (mod x (/ (* n length) 10)))
        (println "in:" (* @sent length) "out:" x))
      (when-let [_ (async/<! output)]
        (recur (inc x)))))) …
Run Code Online (Sandbox Code Playgroud)

memory-leaks asynchronous clojure backpressure core.async

9
推荐指数
1
解决办法
247
查看次数

我可以将Scala列表解构(模式提取)到重用的var中吗?

我有一个Scala列表.我可以将列表解构为一些变量:

var a :: b :: tail = myList
a should be ("A1")
b should be ("B1")
tail should be ('empty)
Run Code Online (Sandbox Code Playgroud)

但是,我似乎无法将相同的变量重用于另一个解构:

a :: b :: tail = anotherList
a should be ("A2")
b should be ("B2")
tail should be ('empty)
Run Code Online (Sandbox Code Playgroud)

编译器告诉我,它期望一个分号,但发现了一个等号.为什么是这样?在解构时是不可能使用已经声明的变量?我做了些蠢事吗?

scala destructuring

6
推荐指数
1
解决办法
2267
查看次数