我正在尝试将 (String, Date) 的 Observable 拆分为两个不同的 Observable 并将它们压缩在一起,如下所示
import monix.execution.Scheduler.Implicits.global
val x = Observable.fromIterator((0 to 10).map(i => (s"a $i", s"b $i")).toIterator)
val y = Observable.toReactive(x)
val fileStream = Observable.fromReactivePublisher(y).mapAsync(5)(a => Task{println(a._1); a._1})
val dateStream = Observable.fromReactivePublisher(y).mapAsync(5)(a => Task{println(a._2); a._2})
fileStream.zip(dateStream)
.map(println)
.subscribe()
但我收到以下异常
monix.reactive.exceptions.MultipleSubscribersException: InputStreamObservable does not support multiple subscribers
at monix.reactive.exceptions.MultipleSubscribersException$.build(MultipleSubscribersException.scala:51)
at monix.reactive.internal.builders.IteratorAsObservable.unsafeSubscribeFn(IteratorAsObservable.scala:42)
at monix.reactive.Observable$$anon$6.subscribe(Observable.scala:155)
at monix.reactive.internal.builders.ReactiveObservable.unsafeSubscribeFn(ReactiveObservable.scala:38)
at monix.reactive.internal.operators.MapAsyncParallelObservable.unsafeSubscribeFn(MapAsyncParallelObservable.scala:60)
at monix.reactive.internal.builders.Zip2Observable.unsafeSubscribeFn(Zip2Observable.scala:158)
at monix.reactive.Observable$$anon$5.unsafeSubscribeFn(Observable.scala:139)
at monix.reactive.Observable$class.subscribe(Observable.scala:71)
at monix.reactive.Observable$$anon$5.subscribe(Observable.scala:136)
at monix.reactive.Observable$class.subscribe(Observable.scala:90)
at monix.reactive.Observable$$anon$5.subscribe(Observable.scala:136)
at monix.reactive.Observable$class.subscribe(Observable.scala:120)
at monix.reactive.Observable$$anon$5.subscribe(Observable.scala:136)
at monix.reactive.Observable$class.subscribe(Observable.scala:112)
at monix.reactive.Observable$$anon$5.subscribe(Observable.scala:136)