[英]ReactiveCocoa subscribe to completed event of flattenmaped signal
This is my code snippet. 这是我的代码段。 The issue is it doesn't reach subscribeCompleted block.
问题是它没有达到subscribeCompleted块。 It supposed to immediately complete as I return empty signal inside flattenmap block.
当我在flattenmap块内返回空信号时,它应该立即完成。 Isn't it?
是不是
RACObserve(self.object, "mobile").skip(2).doNext { (_) -> Void in
self.tabBarController?.showHud("Updating Profile")
}.flattenMap { (object) -> RACStream! in
return RACSignal.empty()
}.subscribeCompleted { () -> Void in
log.error("Completed")
self.tabBarController?.hideHud()
}
The signal returned by flattenMap
will complete only when the "source" signal completes. 仅当“源”信号完成时,
flattenMap
返回的信号才会完成。 In your case you apply flattenMap
operator to the following signal: 在您的情况下,您将
flattenMap
运算符应用于以下信号:
RACObserve(self.object, "mobile").skip(2)
The signal returned by RACObserve
completes only when the object being observed is deallocated. 仅当观察到的对象被释放时,
RACObserve
返回的信号RACObserve
完成。 Depending on what you want to achieve, you can use some operators to transform the signal and get another one that will complete earlier. 根据您要实现的目标,您可以使用一些运算符来转换信号并获得另一个将更早完成的信号。
For example, you can use filter
and take
so that the resulting signal completes after sending its first value matching some conditions: 例如,您可以使用
filter
和take
以便在发送符合某些条件的第一个值后,生成的信号完成:
RACObserve(self.object, "mobile").skip(2).doNext { (_) -> Void in
self.tabBarController?.showHud("Updating Profile")
}.filter {
//some filtering for the value of self.object.mobile
return $0.checkSomeConditions()
}.take(1)
.subscribeCompleted { () -> Void in
log.error("Completed")
self.tabBarController?.hideHud()
}
Note that you don't even need flattenMap
at all. 请注意,您甚至根本不需要
flattenMap
。 The signal will simply complete because of take
operator. 该信号将简单地完成,因为
take
操作员。
可以将flattenMap视为将整个信号转换为空信号的连接,直到每个空信号完成(被flattenMapped的信号完成),才会发送完成信号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.