You can still pattern match on the type, like so: case result: SomeType => complete(result)
-- Johan Akka Team On Fri, Oct 7, 2016 at 4:30 PM, Richard Rodseth <[email protected]> wrote: > You're right the types are different, and PimpedResult is not a case class > so pattern matching doesn't work out. I think I must abandon this approach > and mimic Heiko's. > Was hoping to ease the port from Spray but > this BinTray contribution is too complex. > > Sent from my phone - will be brief > > On Oct 7, 2016, at 1:38 PM, Akka Team <[email protected]> wrote: > > To be fair you are doing something pretty complex with them, but I agree, > the magnet pattern definitely can be humbling. > > Did the code that worked just fine earlier really deal with the exact same > type (tuple with statuscode and APIError)? > > -- > Johan > Akka Team > > On Fri, Oct 7, 2016 at 1:30 PM, Richard Rodseth <[email protected]> > wrote: > >> Heiko has a different approach here >> https://github.com/hseeberger/reactive-flows/blob/master/src >> /main/scala/de/heikoseeberger/reactiveflows/Api.scala >> >> onSuccess(flowFacade ? addFlow) { >> case bc: BadCommand => complete(BadRequest -> bc) >> case fe: FlowExists => complete(Conflict -> fe) >> case fa: FlowAdded => completeCreated(fa.desc.name, fa) >> } >> >> If I recall correctly, the right arrow is creating a tuple. This seems >> like a nice approach, though I suppose it also relies on the untyped nature >> of Ask >> In my case, if I try something like >> >> onSuccess(requestHandler ? NotificationsRequestHandler.AskForStatus) { >> >> case apiError: APIError => complete(StatusCodes.BadRequest >> -> apiError) >> >> ... >> >> } >> >> my implicit conversions to ToResponseMarshallable aren't found, even >> though calling Marshall(reply).to[HttpResponse] a few lines earlier is >> just fine. >> >> Implicit conversions sure are humbling. >> >> On Fri, Oct 7, 2016 at 11:59 AM, Viktor Klang <[email protected]> >> wrote: >> >>> WARNING: I may very well be incorrect here >>> >>> Options: >>> A: switch to the onComplete directive >>> B: map to an Either[Result, PimpedResult]? >>> >>> On Fri, Oct 7, 2016 at 6:38 PM, Richard Rodseth <[email protected]> >>> wrote: >>> >>>> That's the trouble. Depending on whether the actor calls >>>> withStatusCode, it could be a Result or a PimpedResult. Both can be >>>> marshalled. >>>> >>>> In the Spray application we completed the request inside a per-request >>>> actor. That is no longer possible, hence using Ask. >>>> >>>> On Fri, Oct 7, 2016 at 11:18 AM, Akka Team <[email protected]> >>>> wrote: >>>> >>>>> 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/c >>>>>> urrent/additional/faq.html >>>>>> >>>>>>>>>> Search the archives: https://groups.google.com/grou >>>>>> p/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/c >>>>> urrent/additional/faq.html >>>>> >>>>>>>>>> Search the archives: https://groups.google.com/grou >>>>> p/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/c >>>> urrent/additional/faq.html >>>> >>>>>>>>>> Search the archives: https://groups.google.com/grou >>>> p/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. >>>> >>> >>> >>> >>> -- >>> Cheers, >>> √ >>> >>> -- >>> >>>>>>>>>> Read the docs: http://akka.io/docs/ >>> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/c >>> urrent/additional/faq.html >>> >>>>>>>>>> Search the archives: https://groups.google.com/grou >>> p/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/c >> urrent/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. > > -- > >>>>>>>>>> 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.
