I dont need to materialize it more than once. But the concern is understood.

On Tuesday, October 27, 2015 at 3:03:42 PM UTC-4, √ wrote:
>
> This is not going to answer your question but:
>
> def toFlow(handler: Handler) = {
>   var ctxt: Option[Context] = None <--- *DO NOT DO THIS*
>  
>   Flow[(Context, State)].map { 
>     (in: (Context, State)) => {
>         ctxt match {
>           case Some(last) => if (!last.equals(in._1)) {
>             last.concludeContext()
>             ctxt = Some(in._1)
>           } 
>           case None => ctxt = Some(in._1)
>         }
>
>         handler.handleState(in._2) 
>         handler.concludeState(in._2) 
>         in 
>     }       
>   } 
> }
>
> The problem is that now your Flow cannot be materialized more than once 
> (until the previous has run to completion) simply because it is using 
> global mutable state.
>
> On Tue, Oct 27, 2015 at 7:49 PM, Rich Henry <[email protected] 
> <javascript:>> wrote:
>
>> *TL;DR   -- Is there any way to provide an individual Flow component with 
>> logic to execute on Graph completion?*
>>
>> I'm trying to wrap an existing API that is used like this:
>>
>> obj.handleContext(c1)
>> obj.handleState(s1)
>> obj.handleState(s2)
>> obj.handleState(sN)
>> obj.concludeContext(c1)
>>
>> .. in a flow, very much like this:
>>
>> def toFlow(handler: Handler) = {
>>   var ctxt: Option[Context] = None
>>  
>>   Flow[(Context, State)].map { 
>>     (in: (Context, State)) => {
>>         ctxt match {
>>           case Some(last) => if (!last.equals(in._1)) {
>>             last.concludeContext()
>>             ctxt = Some(in._1)
>>           } 
>>           case None => ctxt = Some(in._1)
>>         }
>>
>>         handler.handleState(in._2) 
>>         handler.concludeState(in._2) 
>>         in 
>>     }       
>>   } 
>> }
>>
>>
>> I then combine the various handlers created using this method together 
>> using ~> and use .grouped() and Sink.head to collect the resulting values.
>>
>>
>> *I need to call handler.concludeContext() on the last context passed in 
>> to the flow on completion for each sub-flow.*
>>
>>
>> My backup plan it to wrap the flow components in another class that holds 
>> the context and manually calling the conclude method on them en masse once 
>> the flow completes, but would much prefer to use some built in mechanism 
>> instead if there were one.
>>
>>
>> I'm also open to other strategies that may help me avoid being stateful, 
>> but to date haven't thought of any.
>>
>> (I'm using akka-actor 2.4.0 and akka-streams-experiental 1.0)
>>
>> Thanks,
>> Rich
>>
>> -- 
>> >>>>>>>>>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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 [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.

Reply via email to