-
Notifications
You must be signed in to change notification settings - Fork 7
7. Execution control
Andrii Konovalenko edited this page Apr 12, 2017
·
2 revisions
By default EasyNet execute requests consistently. In most cases this works well, but there are times when it is necessary to execute queries in parallel. To do this, use the parallelExecution() method of the Request class instance.
Example for current request:
EasyNet.get().parallelExecution().start(callback);Example for all requests:
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
EasyNet.getInstance()
.setDefaultNBuilderListener(new EasyNet.NBuilderDefaultListener() {
@Override
public Request defaultConfig(Request request) {
return request
.setHost("http://someurl.com")
.parallelExecution();
}
});
}
}EasyNet class contains Map<String, BaseTask> taskQueue (The queue of requests that are executed or will be executed). Task automatically removed from taskQueue after executing. If you want to interrupt task, you need call removeTask(String tag) method in EasyNet class instance. Tag - unique identificator of current task. Method start() returns task tag (String).
Get task tag:
String tag = EasyNet.get("path").start(callback);Interrupt task:
boolean isInterrupted = EasyNet.getInstance().removeTask(tag); // return true, if task is present and has been interruptedAlso you can interrupt all current tasks:
EasyNet.getInstance().cancelAllTasks();