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反应式编程
Reactive Extensions
39
如果有人进行订阅却只想得到流的一小部分,
Observable 会确保进行资源清理。我们知道
还有第二项实现清理的技术,它不需要等待上游的事件。订阅者取消订阅,样例就立即调
shutdown() 以触发清理行为(最后一行),而不必等待下一条推文到达。
twitterStream.addListener(new StatusListener() {
//回调……
});
twitterStream.sample();
subscriber.add(Subscriptions.create(twitterStream::shutdown));
比较有意思的是,这个 Observable 模糊了
hot
流和
cold
流的差异。一方面,它代表了外
部的事件,这些事件的出现并不受控制(
hot
流的行为)。另一方面,实际订阅之前,事
件并不会开始流动(没有底层的
HTTP
连接)。我们还忽略了另外一个不慎出现的副作
用:每个新的 subscribe() 都会开启一个新的后台线程和一条到外部系统的新连接。相
同的 Observable<Status> 实例应该能够跨多个订阅者实现重用。因为 Observable 是延
迟执行的,所以需要在技术上能够在启动的时候就调用 observe(),并将其保留在某个
单例对象中。但是当前的实现只是简单地打开新连接,为每个 Subscriber 通过网络多次
获取相同的数据。当然,我们想要为这个流注册多个 Subscriber,但是没有理由为每个 ...
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