Skip to content

Commit

Permalink
Wiring up the final call-back correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy committed Jul 23, 2016
1 parent fb0172e commit 686ac75
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface TaskGroup<T, U extends TaskItem<T>> {
* @param callback the callback to call on failure or success
* @return the handle to the REST call
*/
ServiceCall executeAsync(ServiceCallback<Void> callback);
ServiceCall executeAsync(ServiceCallback<T> callback);

/**
* Gets the result of execution of a task in the group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -125,29 +124,14 @@ public void execute() throws Exception {
}

@Override
public ServiceCall executeAsync(final ServiceCallback<Void> callback) {
public ServiceCall executeAsync(final ServiceCallback<T> callback) {
ServiceCall serviceCall = null;
DAGNode<TaskItem<T>> nextNode = dag.getNext();
while (nextNode != null) {
if (dag.isRootNode(nextNode)) {
serviceCall = nextNode.data().executeAsync(this, nextNode, new ServiceCallback<Void>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
}

@Override
public void success(ServiceResponse<Void> result) {
callback.success(result);
}
});
} else {
serviceCall = nextNode.data().executeAsync(this, nextNode, callback);
}

serviceCall = nextNode.data().executeAsync(this, nextNode, dag.isRootNode(nextNode), callback);
if (serviceCall != null) {
// We need to filter out the null value returned by executeAsync. This can
// happen when TaskItem::executeAsync invokes TaskGroupBase::executeAsync
// Filter out the null value returned by executeAsync. that happen
// when TaskItem::executeAsync invokes TaskGroupBase::executeAsync
// but there is no task available in the queue at the moment.
this.serviceCalls.add(serviceCall);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public interface TaskItem<U> {
* @param taskGroup the task group dispatching tasks
* @param node the node the task item is associated with
* @param isRootNode true if the node is root node
* @param callback callback to call on success or failure
* @return the handle of the REST call
*/
ServiceCall executeAsync(TaskGroup<U, TaskItem<U>> taskGroup, DAGNode<TaskItem<U>> node, ServiceCallback<Void> callback);
ServiceCall executeAsync(TaskGroup<U, TaskItem<U>> taskGroup, DAGNode<TaskItem<U>> node, final boolean isRootNode, ServiceCallback<U> callback);
}

0 comments on commit 686ac75

Please sign in to comment.