Hi everyone,
I'm trying to write a function that wraps an arbitrary flow with another flow that performs a side-effect: measures the execution time of the inner flow. I'm also trying to avoid writing a custom GraphStage to do this.
So far, I've come up with this:
def measuredFlow[In, Out](timer: Timer)(flow: Flow[In, Out, NotUsed] = {
Flow[In].flatMapConcat { el =>
val timerContext = timer.timerContext()
Source.single(el).via(flow).map(e => timerContext.close(); e)
}This is great and very composable, but has one restriction: it can only handle flows that I don't care about their materialized values. The reason is that there is no way to propagate the materialized value from within flatMapConcat, AFAICT.
I've been looking for different approaches to this, but couldn't find any that don't involve using flatMapConcat, as that is the only built-in stage that can wrap another stage.
The other solution is to write a custom GraphStage and imitate FlattenMerge's usage of SubSinkInlet, but I'm wary of this as SubSinkInlet is marked as private API and there's no documentation for custom stages that wrap other stages.
Has anyone tried tackling this problem? Would love to hear any ideas.
--
>>>>>>>>>> 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+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.