FlexiMerge seems to be a valid solution to this problem :
class BypassMerge[A, B] extends FlexiMerge[A, FanInShape2[A, B, A]](new
FanInShape2("BypassMerge"), OperationAttributes.name("BypassMerge")) {
def createMergeLogic(p: PortT): MergeLogic[A] = new MergeLogic[A] {
val readA: State[A] = State[A](Read(p.in0)) { (ctx, input, element) ⇒
ctx.emit(element)
readA
}
val readB: State[B] = State[B](Read(p.in1)) { (ctx, input, element) ⇒
readB
}
override def initialCompletionHandling = CompletionHandling (
onUpstreamFinish = { (ctx, input) ⇒
ctx.changeCompletionHandling(defaultCompletionHandling)
readA
},
onUpstreamFailure = { (ctx, _, cause) ⇒
ctx.fail(cause)
SameState
}
)
override def initialState: State[_] = readB
}
}
"Bypass string source with more element" in {
val p = FlowGraph.closed(Sink.publisher[Int]) { implicit b =>
import FlowGraph.Implicits._
sink =>
val merge = b.add(new BypassMerge[Int, String])
Source(List(1,2)) ~> merge.in0
Source(List("1","2","3","4")) ~> merge.in1
merge.out ~> sink.inlet
}.run()
val s = TestSubscriber.manualProbe[Int]
p.subscribe(s)
val sub = s.expectSubscription()
sub.request(10)
s.expectNext(1)
s.expectNext(2)
s.expectComplete()
}
"Bypass string source with less elements" in {
val p = FlowGraph.closed(Sink.publisher[Int]) { implicit b =>
import FlowGraph.Implicits._
sink =>
val merge = b.add(new BypassMerge[Int, String])
Source(List(1,2,3,4)) ~> merge.in0
Source(List("1","2")) ~> merge.in1
merge.out ~> sink.inlet
}.run()
val s = TestSubscriber.manualProbe[Int]
p.subscribe(s)
val sub = s.expectSubscription()
sub.request(10)
s.expectNext(1)
s.expectNext(2)
s.expectNext(3)
s.expectNext(4)
s.expectComplete()
}
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.