RxJS - toBlocking 运算符

RxJS - toBlocking operator

在 RxJava 中有 Observable.toBlocking() 运算符来同步检索 observable 的数据。我找不到 RxJS 的类似运算符。 我想使用这个运算符通过 Rx 改进我的代码,而不使用其他函数式编程库...

schedulers

If you do not provide the scheduler, RxJS will pick a default scheduler by using the principle of least concurrency. This means that the scheduler which introduces the least amount of concurrency that satisfies the needs of the operator is chosen.

只要您不指定调度器,RxJS 本身就会选择一个阻塞调度器/同步解析可观察对象(immediate scheduler) as you can see in this jsbin - 第一个可观察对象在第二个开始之前完成。

如果你想明确地控制并发级别,你可以通过将特定的调度程序传递给支持此选项的运算符来实现。