Skip to content

Request cancelation

Orhan Obut edited this page Aug 25, 2015 · 2 revisions

Use WaspRequest as return type and take the advantage of features such as cancel.

@GET("/repos/{user}/{repo}")
WaspRequest getRepo(
   @Path("user") String user,
   @Path("repo") String repo,
   Callback<Repo> callback
);

WaspRequest request = service.getRepo();
request.cancel();

for multiple requests, use the request manager to cancel all request at once

private final RequestManager requestManager = new SimpleRequestManager();

public void onRefreshData(){
  WaspRequest request = service.getData();
  requestManager.addRequest(request);
}

public void onAnotherNetworkCall() {
  WaspRequest request = service.getFoo();
  requestManager.addRequest(request);
}

public void onDestroy(){
   requestManager.cancelAll();
}
Clone this wiki locally