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反应式编程
42
2
AsyncSubject
记住发布的最后一个值,并且 onComplete() 被调用时,将其推送给所有的订阅者。如
AsyncSubject 没有完成,除了最后一个事件之外,所有的事件都会被丢弃。
BehaviorSubject
在订阅之后,将所有发布的事件推送给订阅者,与 PublishSubject 类似。但是,它首
先会发布在订阅之前发生的最新事件,从而让 Subscriber 立即得到流的状态。比如,
Subject 可能会代表当前的温度,每分钟广播一次。从客户端订阅的时候,他将立即接
收到最新的可见温度,而不用等待几秒再获得下一个事件。但是,同一个 Subscriber
只对最新的温度感兴趣,而不会对历史温度感兴趣。如果此时还没有发布过事件,并且
提供了默认事件,那么将会首先推送一个特殊的默认事件。
ReplaySubject
最有意思的 Subject 类型会缓存贯穿整个历史的推送事件。如果有人订阅,他首先
会接收到一批被错过(缓存)的事件,然后才会实时接收后续的事件。默认情况下,
Subject 创建之后的所有事件都会被缓存。如果流是无穷的或者非常长,这可能会非常
危险(参见
8.6
节)。在这种情况下,可以使用重载版本的 ReplaySubject,它只会保留
如下事件。
在内存中保留可配置数量的事件(createWithSize())。
配置最近事件的时间窗口(createWithTime())。
通过 createWithTimeAndSize() ...
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