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反应式编程
操作符与转换
83
//B
flatMap(innerObs -> just(innerObs)
.delay(rnd.nextInt(5), SECONDS))
在变种
A
中,Observable 会立即出现在外层流中,但是在一定延迟之后才会发布事件。
在变种
B
中,我们及时转移了整个 Observable 的事件,所以它出现在外层 Observable
中的时间要晚得多。现在,已经介绍了为何需要这么复杂的操作符。静态的 concat()
merge() 操作符都能操作由固定列表组成的 Observable,或者由 Observable 组成的
Observable
。而对
switchOnNext()
来说,后者会生效。
switchOnNext() 首先会订阅一个外层的 Observable<Observable<T>>,这个外层 Observable
会发布内层的 Observable<T>。第一个内层 Observable<T> 出现的时候,这个操作符就
会订阅它并开始往下游推送 T 类型的事件。下一个内层 Observable<T> 出现的话,会发
生什么呢? switchOnNext() 将会取消对第一个 Observable<T> 的订阅,从而丢弃第一个
Observable<T>,然后切换至下一个 Observable<T>(这种做法也符合它的名称)。换句话
说,如果有一个用流组成的流时,switchOnNext() 只会往下游转发最后的内部流的事件,
即便旧的流依然在生成新的事件也会被丢弃。 ...
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