Tho*_*eld 2 scala akka akka-stream
Akka 是否试图传达这一点 Source.combine不应该与资源集合一起使用的?或者我对函数定义不知何故?
AkkaSource.combine在 vararags 之前需要第一个和第二个源。函数定义如下:
def combine[T, U](first: Source[T, _], second: Source[T, _], rest: Source[T, _]*)(
strategy: Int => Graph[UniformFanInShape[T, U], NotUsed]
Run Code Online (Sandbox Code Playgroud)
我只想做这样的事情:
val sources : Seq[Source[Int,_]] = ???
Source.combine(sources:_*)(Merge(_))
Run Code Online (Sandbox Code Playgroud)
我不知道我sources是否会有 1,2 或许多来源。所以写案例增加了几行。没什么大不了的,但我觉得我错过了一些东西。这是 akka 流的反模式吗?
花纹的要点 first: Source[T, _], second: Source[T, _], rest: Source[T, _]*是确保您将至少 2 个(可能更多)源传递给方法。
如果允许方法签名 sources:_*您可以传递空的 vararg 或仅传递单个元素。
在您的情况下,如果源是Seq,我只会对源进行模式匹配以拆分为第一个和第二个元素以及其余元素:
sources match {
case first :: second :: rest => Source.combine(first, second, rest:_*)(Merge(_))
case _ => ??? // too few elements, maybe return Source.failed?
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
44 次 |
| 最近记录: |