I would like to change the following code fragment in a way that I want to factor out the onSuccess block into a new method. JSON marshalling should still work.
(patch & parameterMap & asJson) { params =>
...
val f:Future[ResposeData]=createResponse(...)
onSuccess(f){complete(_)}
}
I would like to have a method like:
def handleSuccess(f:Future/FutureMagnet)(implicit ...)
A simple refactoring doesn't work for me. I tried a lot of combinations but I can't find either the correct signature or the code working.
Example:
def handleSuccess(f: Future[ResposeData]): Unit = {
onSuccess(f) { complete(_) }
}
Error:(43, 15) type mismatch;
found : scala.concurrent.Future[ResponseData]
required: spray.routing.directives.OnSuccessFutureMagnet
onSuccess(f) {
^
If I now change signature I get another error:
def handleSuccess(f: OnSuccessFutureMagnet)
Error:(44, 18) spray.routing.Directive[f.Out] does not take parameters
onSuccess(f) {
^
Maybe this is just a simple thing to do but I'm new to spray. So it would be nice if somebody could give a hint.
Thanks