- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在阅读 Packt ( https://www.oreilly.com/library/view/reactive-programming-with/9781787120211/) 撰写的关于 RxSwift 的书“使用 Swift 4 进行响应式编程”。在一节中,这本书说:
"Disposing of a subscription will cause the underlying Observable sequence to emit a completed event and terminate"
但是我发现这个短语是不正确的。这是一个例子:
let publisher = PublishSubject<Int>() //Create an <Int> sequence
let subscription1 = publisher.asObservable() //Create 1st subscription
.debug("Subscription 1")
.subscribe { (event) in
print(event)
}
let subscription2 = publisher.asObservable() //Create 2nd subscription
.debug("Subscription 2")
.subscribe { (event) in
print(event)
}
publisher.onNext(1) //Emit first event
subscription1.dispose() //Dispose the 1st subscription. According to the phrase above, publisher should emit an onComplete event
publisher.onNext(2) //Emit second event
正如我在代码中的评论所说,在 subscription1.dispose() 处,publisher 应该发出 onComplete 事件,但实际上它仍然可以发出新事件像往常一样,因此输出:
2018-11-01 19:43:59.796: Subscription 1 -> subscribed
2018-11-01 19:43:59.798: Subscription 2 -> subscribed
2018-11-01 19:43:59.798: Subscription 1 -> Event next(1)
next(1)
2018-11-01 19:43:59.798: Subscription 2 -> Event next(1)
next(1)
2018-11-01 19:43:59.799: Subscription 1 -> isDisposed
2018-11-01 19:43:59.799: Subscription 2 -> Event next(2)
next(2)
谁能证实我的理解是正确的?还是我错过了 RxSwift 幕后的任何东西?
提前致谢
最佳答案
您对取消订阅的理解是正确的:处理订阅不会导致 onComplete 运行。但是,当达到 onComplete 或 onError 时,它将自动取消订阅(http://reactivex.io/documentation/contract.html 订阅和取消订阅部分非常有用)
关于swift - RxSwift - 处理订阅是否会导致底层序列发出 onComplete?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53101662/
查看Java库中的代码块AsyncHttpClient ,客户端启动一个新线程(Future)来发出请求。回调是在同一个线程上发生,还是在“主”线程上运行(在本例中,是调用 new AsyncHttp
我的 Controller对象使用 Renci.SshNet 通过 SSH 调用 MySQL 数据库,因为我连接到多个数据库,所以我转向多线程,函数 af.FetchAll()返回 DataSet ,
据我们所知,我们有 onComplete和 onAbort可选回调作为 router.push 中的第二个和第三个参数方法。 router.push(location, onComplete?, on
我正在尝试为 Android 制作一个应用程序。 该应用程序必须有一个登录和注册表单,我不明白为什么方法 onComplete 不起作用,但数据被添加到注册页面的数据库中。 这是代码: private
我想获取使用 windows azure 完成的查询的结果。 private boolean checkIfExist(Client c) { this.clientTable.where()
在 RxJava2 中,这是我的代码: public void myMethod() { Flowable.create(e->{ // do sth. }, BackpressureStrate
我在我的父类中发布了一个 MediaPlayer 成员变量,在我启动它之后,它永远不会调用 onCompletion,或者至少 onCompletionListener 永远不会捕获它?我的代码看起来
通过使用 RxSwift,我的项目的目的是每当用户在搜索栏中键入一个城市时,它都会调用以包装当前温度。目前,我有 viewModel 其中包含 var searchingTerm = Variable
所以,我在 MVC 4 应用程序中使用 FineUploader 3.3,这是一个非常酷的插件,非常值得象征性的成本。现在,我只需要让它正常工作。 我对 MVC 很陌生,对传回 JSON 完全陌生,所
我正在尝试通过 jwplayer().getPlaylistItem().file; 获取视频的 URL onComplete 回调,但它什么也没返回。 jwplayer().onComplete(f
我有一个 Future[Future[Set[String]]。我将其平面化以返回 Future[Set[String]]。我等待无穷大(我知道这很糟糕)然后检查 Future 是否完成。它返回真。但
我正在使用以下源代码通过 jwpalyer 显示视频文件。 jwplayer('mediaplayer').setup({ 'id': 'mediaplayer', 'width'
我在 View 模型中有这个主题: private PublishSubject articleSubject; public Observable newArticleSubject() {
由于某种原因,它只是没有运行 onComplete 函数。然而它确实加载了 fancybox div。我的html: #1 click here
我想在单击提交按钮时调用 JavaScript 函数。我使用了 form_tag ,但该函数没有被触发。我想要如下所示的内容: 'start_form_request(); ' ,:onComple
我想在表单加载后调用 onclick 事件。我没有找到 onCompletion 事件或任何类似的事件 类似于:kind: someUI, onComplete:“Init” 最佳答案 根据您的描述,
有人可以指出在哪里可以找到带有 onComplete 回调的命令模式的实现吗?例如可以在串行宏命令中使用该回调? 最佳答案 试试这个 abstract class Command { fina
函数体是否传递给 Future.onComplete(),它们的闭包是否在调用后被丢弃并因此被垃圾收集? 我问是因为我正在编写无限序列的 Future 实例。每个 Future 都有一个 .onCom
我编写的以下方法运行良好,位于我的 Utils 包中,我从我的一些 Activity 中调用它。 private static Date date = null; public static Date
我正在使用 spring-mvc 和 jquery uploadify 上传图像,我的 uploadify 脚本将图像保存在我的服务器上,我的图像正在保存,但 uploadify 抛出 HTTP 错误
我是一名优秀的程序员,十分优秀!