All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.objectify.impl.ResultAdapter Maven / Gradle / Ivy

There is a newer version: 6.1.2
Show newest version
package com.googlecode.objectify.impl;

import com.googlecode.objectify.Result;
import com.googlecode.objectify.util.FutureHelper;

import java.util.concurrent.Future;

/**
 * Adapts a Future object to a (much more convenient) Result object.
 *
 * @author Jeff Schnitzer 
 */
public class ResultAdapter implements Result
{
	/** Cuts out some typing */
	public static  ResultAdapter create(Future fut) {
		return new ResultAdapter<>(fut);
	}

	/** */
	Future future;

	/** */
	public ResultAdapter(Future fut)
	{
		this.future = fut;
	}

	@Override
	public T now()
	{
		try
		{
			return this.future.get();
		}
		catch (Exception e)
		{
			FutureHelper.unwrapAndThrow(e);
			return null;	// make compiler happy
		}
	}
}