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

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.

主站蜘蛛池模板: 海阳市| 濮阳县| 张北县| 前郭尔| 山阳县| 华蓥市| 合江县| 衡山县| 启东市| 平顺县| 芦山县| 大兴区| 九龙县| 潍坊市| 岐山县| 灵石县| 天津市| 金寨县| 香港 | 天长市| 明水县| 新宾| 西平县| 宁武县| 团风县| 辛集市| 潜山县| 高安市| 三亚市| 隆子县| 昔阳县| 宜黄县| 辽阳县| 山西省| 嘉善县| 铁岭市| 托克逊县| 澳门| 宜春市| 安顺市| 房山区|