It required a little bit of Round Robing : -) 

class RoundRobinBypassingMerge[A, B] extends FlexiMerge[A, FanInShape2[A, B, 
A]](new FanInShape2("RRBMerge"), OperationAttributes.name("RRBMerge")) {
  def createMergeLogic(p: PortT): MergeLogic[A] = new MergeLogic[A] {


    val read1: State[A] = State[A](Read(p.in0)) { (ctx, input, element) =>
      ctx.emit(element)
      read2
    }
    val read2: State[B] = State[B](Read(p.in1)) { (ctx, input, element) =>
      read1
    }
    val readRemaining1: State[A] = State[A](Read(p.in0)) { (ctx, input, 
element) =>
      ctx.emit(element)
      SameState
    }
    val readRemaining2: State[B] = State[B](Read(p.in1)) { (ctx, input, 
element) =>
      SameState
    }


    override def initialState: State[_] = read1


    override def initialCompletionHandling = CompletionHandling(
      onUpstreamFinish = { (ctx, input) ⇒
        ctx.changeCompletionHandling(defaultCompletionHandling)
        if (input eq p.in0) readRemaining2 else readRemaining1
      },
      onUpstreamFailure = { (ctx, _, cause) ⇒
        ctx.fail(cause)
        SameState
      })


  }
}



-- 
>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to