什么是 Akka (Scala) 中的 Int 和 Out 类型
What is Int, Out type in Akka (Scala)
我正在研究 Akka Stream。当我读到一个关于 Akka Balance 的例子时。
本例中的 In 和 Out 类型是什么?
def balancer[In, Out](worker: Flow[In, Out, Any], workerCount: Int): Flow[In, Out, NotUsed] = {
import GraphDSL.Implicits._
Flow.fromGraph(GraphDSL.create() { implicit b ⇒
val balancer = b.add(Balance[In](workerCount, waitForAllDownstreams = true))
val merge = b.add(Merge[Out](workerCount))
for (_ ← 1 to workerCount) {
// for each worker, add an edge from the balancer to the worker, then wire
// it to the merge element
balancer ~> worker.async ~> merge
}
FlowShape(balancer.in, merge.out)
})
}
val processedJobs: Source[Result, NotUsed] = myJobs.via(balancer(worker, 3))
Flow
A processing stage which has exactly one input and output, which
connects its up- and downstreams by transforming the data elements
flowing through it.
一般来说,In
和Out
就是type parameters。具体来说,它们用于传送 输入类型,这是您放入流中的类型,以及 输出类型,这是由流。
我正在研究 Akka Stream。当我读到一个关于 Akka Balance 的例子时。
本例中的 In 和 Out 类型是什么?
def balancer[In, Out](worker: Flow[In, Out, Any], workerCount: Int): Flow[In, Out, NotUsed] = {
import GraphDSL.Implicits._
Flow.fromGraph(GraphDSL.create() { implicit b ⇒
val balancer = b.add(Balance[In](workerCount, waitForAllDownstreams = true))
val merge = b.add(Merge[Out](workerCount))
for (_ ← 1 to workerCount) {
// for each worker, add an edge from the balancer to the worker, then wire
// it to the merge element
balancer ~> worker.async ~> merge
}
FlowShape(balancer.in, merge.out)
})
}
val processedJobs: Source[Result, NotUsed] = myJobs.via(balancer(worker, 3))
Flow
A processing stage which has exactly one input and output, which connects its up- and downstreams by transforming the data elements flowing through it.
一般来说,In
和Out
就是type parameters。具体来说,它们用于传送 输入类型,这是您放入流中的类型,以及 输出类型,这是由流。