Skip to content

Commit

Permalink
Make ServiceCall Future-like
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Aug 2, 2016
1 parent 4660eff commit e952c39
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@

package com.microsoft.rest;

import com.google.common.util.concurrent.AbstractFuture;

import retrofit2.Call;

/**
* An instance of this class provides access to the underlying REST call invocation.
* This class wraps around the Retrofit Call object and allows updates to it in the
* progress of a long running operation or a paging operation.
*
* @param <T> the type of the returning object
*/
public class ServiceCall {
public class ServiceCall<T> extends AbstractFuture<T> {
/**
* The Retrofit method invocation.
*/
Expand Down Expand Up @@ -62,4 +66,26 @@ public void cancel() {
public boolean isCanceled() {
return call.isCanceled();
}

/**
* Invoke this method to report completed, allowing
* {@link AbstractFuture#get()} to be unblocked.
*
* @param result the object returned.
* @return true if successfully reported; false otherwise.
*/
public boolean success(T result) {
return set(result);
}

/**
* Invoke this method to report a failure, allowing
* {@link AbstractFuture#get()} to throw the exception.
*
* @param t the exception thrown.
* @return true if successfully reported; false otherwise.
*/
public boolean failure(Throwable t) {
return setException(t);
}
}

0 comments on commit e952c39

Please sign in to comment.