Avoiding excessive continuations

18 views
Skip to first unread message

Rick Mann

unread,
Oct 13, 2016, 6:07:01 AM10/13/16
to Baratine
As I'm adding functionality to my app, I'm starting to get mired in nested continuations. Is it possible to enter the first continuation, then write a set of synchronous code, then finish the continuation to respond to the client?

Obviously that's true, but I'm not quite sure how to make some of the calls. Take this method, for example <https://github.com/JetForMe/hoa/blob/master/src/main/java/com/latencyzero/hoa/AbstractHOASession.java#L37>. It calls mUsers.create(), which takes a continuation that eventually calls user.get(), with yet another continuation. Once I'm in the first continuation, I'm on another thread, right? I can just do the rest of the work synchronously?

I thought I read something that calls can be made continuation-style, or synchronously by treating them as if they return a result, but I can't get my naive attempt to work. Can that method be simplified?

Thanks.

--
Rick Mann
rm...@latencyzero.com


Alex Rojkov

unread,
Oct 13, 2016, 2:26:36 PM10/13/16
to Rick Mann, Baratine
You can try extracting the actual code in a method. That way in the
continuation you'll only have a call to the method that actually does
the more complicated work.

This approach should make the code easier to read.

Like in this login method in the Auction, which just calls to
authenticate() for the actual work:

https://github.com/baratine/auction/blob/master/src/main/java/examples/auction/AbstractAuctionSession.java#L76

Thanks,

Alex
> --
> You received this message because you are subscribed to the Google Groups "Baratine" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to baratine-io...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages