Hi Richard,

You can combine ask with mapTo to cast it to the right type (or fail the
future if it does not have that type), see the docs here:
http://doc.akka.io/docs/akka/2.4/scala/futures.html#use-with-actors

--
Johan
Akka Team

On Fri, Oct 7, 2016 at 10:55 AM, Richard Rodseth <[email protected]> wrote:

> Continuing my struggles to port something we did with Spray, using
>
> // See https://bitbucket.org/binarycamp/spray-contrib/src
>
> I have resolved my implicit conversion errors to the point where I can
> execute the following (Result[T] is an alias for Either[APIError, T]):
>
>   val successResult: Result[NotificationsStatusDTO] =
> Right(NotificationsStatusDTO("foo"))
>
>   val successResponseFuture: Future[HttpResponse] = Marshal(successResult
> ).to[HttpResponse]
>
>   val successResponse = Await.result(successResponseFuture, 1.second) //
> don't block in non-test code!
>
>   println(s"Success response $successResponse")
>
>   val successResult2: Result[NotificationsStatusDTO] =
> Right(NotificationsStatusDTO("foo"))
>
>   val resultWithStatusCode: PimpedResult[(StatusCode,
> NotificationsStatusDTO)] = successResult2.withStatusCode(
> StatusCodes.Accepted)
>
>   val successResponseWithStatusCodeFuture: Future[HttpResponse] = Marshal(
> resultWithStatusCode).to[HttpResponse]
>
>   val successResponseWithStatusCode = Await.result(successResponseWi
> thStatusCodeFuture, 1.second) // don't block in non-test code!
>
>   println(s"Success with status code $successResponseWithStatusCode")
>
> But I have not been able to figure out how to use the onSuccess directive
> (or another if more appropriate) if the response (either a Result or a
> PimpedResult as above) is coming from an Ask.
>
> This obviously doesn't work:
>
>           onSuccess(requestHandler ? NotificationsRequestHandler.AskForStatus)
> {
>
>             case _ => complete(x)
>
>           }
>
> Any pointers?
>
> --
> >>>>>>>>>> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.

-- 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to