gpt4 book ai didi

ios - 关于自定义 RxSwift Observable 扩展的问题

转载 作者:行者123 更新时间:2023-11-28 13:50:15 25 4
gpt4 key购买 nike

extension Observable {
func dispatchAsyncMainScheduler() -> Observable<E> {
return self.observeOn(backgroundScheduler).observeOn(MainScheduler.instance)
}
}

我在 https://github.com/artsy/eidolon 中找到了这段代码

我是这里的 reactive 初学者。据我了解。 subscribeOn 应用于整个链,而 observeOn 应用于其下方的运算符。

我的问题很明显,这两个连续的 observeOn 到底做了什么?

最佳答案

这不是打字错误。如果您查看此运算符上方 10 行的 backgroundScheduler 定义,您会发现它是一个 SerialDispatchQueueSceduler。这意味着它将操作排队并在后台线程上按顺序执行它们。

他们使用它来避免重入异常。我假设这段代码是在 MainScheduler.asyncInstance 被放入库之前编写的,它做同样的事情。

可以在 Rx 库中找到更多信息:

  • Problem: This behavior is breaking the observable sequence grammar. next (error | completed)? This behavior breaks the grammar because there is overlapping between sequence events. Observable sequence is trying to send an event before sending of previous event has finished.
  • Interpretation: This could mean that there is some kind of unexpected cyclic dependency in your code, or that the system is not behaving in the expected way.
  • Remedy: If this is the expected behavior this message can be suppressed by adding .observeOn(MainScheduler.asyncInstance) or by enqueing sequence events in some other way.

关于ios - 关于自定义 RxSwift Observable 扩展的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54745255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com