Skip to Content
RxJava反应式编程
book

RxJava反应式编程

by Tomasz Nurkiewicz, Ben Christensen
December 2019
Beginner to intermediate
330 pages
10h 7m
Chinese
Posts & Telecom Press
Content preview from RxJava反应式编程
流控制和回压
179
它必须在我们想要停止采样的时候完成。第二个流的完成标志着给定批次的结束。这里需
要仔细观察:我们想要开始一个新的批次时,
openings 流会发布一个事件。对于 openings
发布的每个事件,样例都会返回一个新的 Observable,它应该在未来的某个时间点完成。
例如,openings 发布一个值为 Duation.ofMillis(100) 的事件时,样例将其转换为一个
Observable,它会在给定的批次结束时完成,在这里也就是
100
毫秒之后。注意,在连续
的批次中,有些事件可能会被丢弃或重复出现。如果第二个 Observable,也就是负责标记
给定批次完成的 Observable,出现在下一个批次的开始事件之前,那么在这个时间差之内
的事件将会被 buffer() 丢弃。具体到这里:每秒(在业务时间之外是其他间隔秒数)都会
缓冲事件,但是缓冲区会在
100
毫秒(或者
200
毫秒,视情况而定)之后关闭,缓冲内容
会被转发至下游。大多数事件都会落在缓冲时段中,因此会被丢弃。
buffer()
操作符非常灵活和复杂。请你用它做一些试验性的尝试并确保理解了上述样例。
它能够非常智能地批量处理来自上游的事件,从而实现分组、采样和窗口移动的功能。但
是,
buffer()
关闭当前缓冲时需要创建一个中间的
List
,然后才能将其传递到下游,这可
能会给垃圾回收和内存使用带来不必要的压力(参见
8.6
节)。因此,
window()
操作符应运
而生。
6.1.3
 窗口移动
我们在使用 buffer() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Java并发编程

Java并发编程

道格拉斯·施密特
Spark快速大数据分析(第2版)

Spark快速大数据分析(第2版)

Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee

Publisher Resources

ISBN: 9787115524003