Akka-http directive for running code after response is sent?

22 views
Skip to first unread message

Daniel Armak

unread,
Jan 11, 2018, 11:54:56 AM1/11/18
to Akka User List

Is there a way to be notified when a response has been sent to the client?

I’d like to cleanup some resources used to produce the response after I know it has been sent and that the non-strict HttpEntity I created will not be accessed again. After the cleanup runs, trying to materialize the entity data stream again would fail.
The closest approximation I’ve found so far is to use mapRouteResult to call response.entity.transformDataBytes and use Flow.concat to run the code when the stream has been consumed (or fails). This seems imperfect, because it’s possible that the entity will be consumed more than once (in other word, the entity stream might be materialized more than once), e.g. by a badly coded outer directive. I’m not really worried that this will happen (without my tests catching it), but if there’s a better way I’d like to know about it.

Thanks,

-- 
Daniel Armak


Martynas Mickevičius

unread,
Jan 12, 2018, 3:04:14 AM1/12/18
to akka...@googlegroups.com
Hi,

if you complete a request with a `Source` you can attach cleanup actions using watchTermination.

--
>>>>>>>>>> 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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages