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

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.

主站蜘蛛池模板: 明溪县| 扬州市| 济宁市| 河北区| 镇原县| 旅游| 永和县| 营山县| 曲阳县| 阿勒泰市| 正宁县| 沅江市| 津市市| 松滋市| 将乐县| 洛南县| 柳林县| 两当县| 南充市| 安达市| 哈尔滨市| 砚山县| 桃园县| 禹州市| 虎林市| 美姑县| 大洼县| 广东省| 四子王旗| 昭平县| 深泽县| 射阳县| 龙里县| 维西| 旌德县| 平邑县| 南和县| 梁平县| 绿春县| 咸宁市| 定结县|