Re: [akka-user] [Akka Stream] Happens-before relation and runForEach

2017-02-07 Thread hbf
Thanks, Roland and √. My example was indeed made up (there are better constructs in place) but thanks for clarifying that it's indeed the JVM happens-before relations that applies. – Kaspar On Wednesday, September 21, 2016 at 12:56:41 AM UTC-7, √ wrote: > > Technically I think the solution

Re: [akka-user] [Akka Stream] Happens-before relation and runForEach

2016-09-21 Thread Viktor Klang
Technically I think the solution holds water, there are appropriate barriers in place. (multi-materialization aside) However, as mentioned, fold() would be a much cleaner, safer and maintainable solution. -- Cheers, √ On Sep 21, 2016 07:05, "Roland Kuhn" wrote: >

Re: [akka-user] [Akka Stream] Happens-before relation and runForEach

2016-09-20 Thread Roland Kuhn
Technically I'm not sure this is correct: since f is only called from within a single operator (and assuming only a single materialization) the shown code should work just fine. Of course it is necessary to know what you're doing when coding like this, and as Konrad says there are better

Re: [akka-user] [Akka Stream] Happens-before relation and runForEach

2016-09-20 Thread hbf
Thanks for clarifying, Konrad. – Hbf On Tuesday, September 20, 2016 at 4:33:53 PM UTC-7, Konrad Malawski wrote: > > > final Source source = // ... > final MutableInt max = new MutableInt(Integer.MIN_VALUE); > final Procedure f = i -> { > if (i >

Re: [akka-user] [Akka Stream] Happens-before relation and runForEach

2016-09-20 Thread Konrad Malawski
final Source source = // ... final MutableInt max = new MutableInt(Integer.MIN_VALUE); final Procedure f = i -> { if (i > max.intValue()) { max.setValue(i); } }; final CompletionStage result = source .runForeach(f, materializer)

[akka-user] [Akka Stream] Happens-before relation and runForEach

2016-09-20 Thread hbf
Hey everybody, Akka Stream may execute the function given to Source.runForEach() from different threads. Therefore, if this function has state, it may need some synchronization. For example: final Source source = // ... final MutableInt max = new