官术网_书友最值得收藏!

Dropping buffer

A dropping buffer also has a fixed size. However, instead of blocking producers when it is full, it simply ignores any new items, as shown here:

    (def result (chan (async/dropping-buffer 2)))
    (go-loop []
      (<! (async/timeout 1000))
      (when-let [x (<! result)]
        (prn "Got value: " x)
        (recur)))
    
    (go  (doseq [n (range 5)]
           (>! result n))
         (prn "Done putting values!")
         (async/close! result))
    
    ;; "Done putting values!"
    ;; "Got value: " 0
    ;; "Got value: " 1  

As before, we still have a buffer of size two, but this time, the producer ends quickly without ever getting blocked. The dropping-buffer simply ignored all items over its limit.

主站蜘蛛池模板: 清流县| 应城市| 山丹县| 阿坝| 峡江县| 沈阳市| 巍山| 江安县| 鄱阳县| 交口县| 五华县| 封开县| 都安| 恩平市| 定日县| 丰原市| 灯塔市| 新蔡县| 托克逊县| 凤凰县| 六枝特区| 修水县| 闽清县| 长岛县| 东辽县| 旌德县| 大竹县| 绥宁县| 江阴市| 阿荣旗| 兴安盟| 红河县| 金沙县| 安乡县| 霍山县| 博客| 大埔县| 鹿泉市| 红河县| 台前县| 黎城县|