0
votes

I have an object that I use for temporary data storage using Objectify on App Engine.

When I save my entity, if it throws an ApiProxy.RequestTooLargeException I clear out some of the data and resave. I want to do this Asyncronously, but can't work out how to catch and handle async save errors.

Saving synchronously it works fine, something like this:

private void save() {
    try {
        ofy().save().entity(this).now();
    } catch (ApiProxy.RequestTooLargeException e) {
        clearOldData();
        save();
    }
}

How can I do a similar thing with an async save?

1

1 Answers

1
votes

You only get an exception when the now() method is called. So save the Result<?> object and call now() when you are ready. Use a filter and a thread local if you want; this is effectively what Objectify does.

If you're looking for callback-style async interfaces, they don't exist. And they wouldn't be any better than holding the Result<?>s till the end of the request and finishing them off yourself.