- Hands-On Reactive Programming with Clojure
- Konrad Szydlo Leonardo Borges
- 194字
- 2021-07-02 14:03:56
Backpressure strategies
If an observable doesn't support backpressure but we are still interested in all of the items it emits, we can use one of the built-in backpressure combinators provided by Rx.
As an example, we will look at one such combinator, onBackpressureBuffer:
(rx/subscribe (->> (rx/map vector
(.onBackpressureBuffer (fast-producing-obs))
(slow-producing-obs))
(rx/map (fn [[x y]]
(+ x y)))
(rx/take 10))
prn-to-repl
(fn [e] (prn-to-repl "error is " e))) ;; 2 ;; 4 ;; 6 ;; 8 ;; 10 ;; 12 ;; 14 ;; 16 ;; 18 ;; 20
This example is very similar to the one where we used sample, but the output is fairly different. This time, we get all of the items that have been emitted by both observables.
The onBackpressureBuffer strategy implements a strategy that simply buffers all of the items that are emitted by the slower Observable, emitting them whenever the consumer is ready. In our case, this happens every 500 milliseconds.
Other strategies include onBackpressureDrop and onBackpressureBlock.
It's worth noting that Reactive pull backpressure is still a work in progress and the best way to keep up to date with progress is on the RxJava wiki on the subject: https://github.com/ReactiveX/RxJava/wiki/Backpressure.
- 腦深部電刺激術(shù)
- 實(shí)用口腔正畸臨床技術(shù)圖譜
- 嗜鉻細(xì)胞瘤、副神經(jīng)節(jié)瘤及相關(guān)綜合征
- 角膜上皮細(xì)胞功能障礙診療圖解(眼表疾病臨床系列)
- 狡猾的細(xì)胞:癌癥的進(jìn)化故事與治愈之道
- 突面畸形的正畸策略及技術(shù)
- 得覺(jué)的力量
- 圖說(shuō)災(zāi)難逃生自救叢書(shū):海嘯
- 實(shí)用肝膽病臨床手冊(cè)
- 災(zāi)難醫(yī)學(xué):管理篇
- 紫外線皮膚科實(shí)戰(zhàn)口袋書(shū)
- 臨床麻醉難點(diǎn)解析(第2版)
- 中西醫(yī)專(zhuān)家?guī)湍庾x痤瘡
- 急危重癥容量管理
- 化妝品生產(chǎn)質(zhì)量管理規(guī)范240問(wèn)