我使用Project Reactor流实现在Scala中实现了简单流。
val iterators: Iterable[Flux[String]] = for (i <- 0 to 4000) yield Flux.interval(5 seconds).map(_.toString)
val publishers: Flux[Flux[String]] = Flux.just(iterators).flatMapIterable(identity)
Flux.merge(publishers, 1)
试图编译该代码但出现错误
Error:(156, 8) overloaded method value merge with alternatives:
[I](prefetch: Int, sources: org.reactivestreams.Publisher[_ <: I]*)reactor.core.scala.publisher.Flux[I] <and>
[I](sources: org.reactivestreams.Publisher[_ <: I]*)reactor.core.scala.publisher.Flux[I] <and>
[T](source: org.reactivestreams.Publisher[org.reactivestreams.Publisher[_ <: T]], concurrency: Int)reactor.core.scala.publisher.Flux[T]
cannot be applied to (reactor.core.scala.publisher.Flux[reactor.core.scala.publisher.Flux[String]], Int)
为什么scala无法转换这些类型?
[Flux.merge(publishers)
效果很好,但是当我传递整数参数时,scala编译器会因错误而失败。
如果使用反应堆标量扩展,则以相反的方式应用它。
Flux.merge(1, publishers)