On Fri, Jun 12, 2015 at 3:40 PM, Eric Kolotyluk <eric.koloty...@gmail.com>
wrote:

> Thanks; so my new code is
>
>   logger.info("Create a Source based on a simple Iterable[T]")
>   val source = Source(1 to 10)
>
>   logger.info("create redundant flow1 because of Akka Streams API design
> limitations")
>   val flow1 = Flow[Int].map(int => int)
>
>   logger.info("Create sink1 that can be connected to the Source" )
>   //val sink1 = Sink.foreach { int: Int => logger.info("sink1: " + int) }
>   val sink1 = Sink.foreach{ int: Int => logger.info("sink1: " + int) }
>
>   logger.info("Connect the Source to the sink1, obtaining a runnableFlow1"
> )
>   //val runnableFlow1: RunnableFlow[Unit] = source.to(sink1)
>   val runnableFlow1 = (source via flow1).toMat(sink1)(Keep.right)
>
>   logger.info("Create flowMaterializer1")
>   val flowMaterializer1 = ActorFlowMaterializer()
>
>   logger.info("Materialize runnableFlow1 as materializedFlow1")
>   val materializedFlow1 = runnableFlow1.run()(flowMaterializer1)
>
>   materializedFlow1.onComplete(result => system.shutdown())
>
> I wish this did not have to be so complicated. While I understand this is
> still experimental, I hope some effort goes into simplifying the API
> design. In particular, in my original code, I don't understand why
> materializedFlow1 is Unit and not Future[Unit].
>

run() returns Unit because that is the MaterializedType of `flow1`, since
Akka Streams preserve the leftmost MaterializedType when chaining
operations (source via flow1 to sink1) in this case, if you wnat to
override that, you'll need to be explicit about it, hence the "toMat"
(terribly named method, I agree). "Keep" is a set of functions that is nice
to reuse for clarity, you could also write `toMat(sink1)((a,b) => b)`


> Also, why do explicitly need to create the Flow, why can't the
> FlowMaterializer do that implicitly if it needs to?
>

I have no idea what you mean here. If you want to run it immediately you
can use `runWith(sink)`.


>
> Sadly Keep is not defined in
> http://doc.akka.io/api/akka-stream-and-http-experimental/0.10/#akka.stream.scaladsl.package
> so there is no way to know what it does.
>
>
In your IDE, you can go to definition if you are unsure. Otherwise The
ScalaDoc for `toMat` should be clear.


> Also, is there some overriding reason that the method .toMat() cannot
> simply be called .toMaterializer()?
>

Because it doesn't create a materializer. But OTOH I agree that it is
terribly named. I'd vote for fixing it. Perhaps by defining `to` as:

def to[Mat2, Mat3](sink: Graph[SinkShape[Out], Mat2], combine: (Mat,
Mat2) ⇒ Mat3 = Keep.left): Sink[In, Mat3]



>
> - Eric
>
> On Thursday, 11 June 2015 15:40:48 UTC-7, √ wrote:
>>
>> Hi Eric,
>>
>> You'll need to instruct the connect of the Sink to keep its materialized
>> value rather than the Flows:
>>
>> val src = Source(immutable.Seq(1,2,3))
>> val flo = Flow[Int].map(_ * 2)
>> val sin = Sink.foreach(println)
>> val runFlow = (src via flo).toMat(sin)(Keep.right)
>> val fut = runFlow.run()
>>
>> fut.onComplete(_ => sys.shutdown())
>>
>>
>> On Thu, Jun 11, 2015 at 6:26 PM, Eric Kolotyluk <eric.ko...@gmail.com>
>> wrote:
>>
>>> I have some simple code
>>>
>>>   logger.info( "Hello World!" )
>>>
>>>   implicit val system = ActorSystem("System")
>>>   import system.dispatcher
>>>
>>>   logger.info("Create a Source based on a simple Iterable[T]")
>>>   val source = Source(1 to 10)
>>>
>>>   logger.info("Create sink1 that can be connected to the Source" )
>>>   val sink1 = Sink.foreach { int: Int => logger.info("sink1: " + int) }
>>>
>>>   logger.info("Connect the Source to the sink1, obtaining a
>>> runnableFlow1")
>>>   val runnableFlow1: RunnableFlow[Unit] = source.to(sink1)
>>>
>>>   logger.info("Create flowMaterializer1")
>>>   val flowMaterializer1 = ActorFlowMaterializer()
>>>
>>>   logger.info("Materialize runnableFlow1 as materializedFlow1")
>>>   val materializedFlow1 = runnableFlow1.run()(flowMaterializer1)
>>>
>>>   // How do I know when materializedFlow1 is finished so I can shut
>>> down the actor system?
>>>
>>> Cheers, Eric
>>>
>>> --
>>> >>>>>>>>>> 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+...@googlegroups.com.
>>> To post to this group, send email to akka...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Cheers,
>> √
>>
>  --
> >>>>>>>>>> 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.
>



-- 
Cheers,
√

-- 
>>>>>>>>>>      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