The use of jdeferred library
class=”htmledit_views”> How to use and test apply plugin: ‘java-library’ dependencies { implementation fileTree(dir: ‘libs’, include: [‘*.jar’]) compile ‘org.jdeferred.v2:jdeferred-core:2.0.0-beta2’ compile ‘org.slf4j:slf4j-simple:1.7.7’ // compile ‘org.jdeferred:jdeferred-android-aar:1.2.4’ } //org.slf4j // slf4j-simple //1.7.7 sourceCompatibility = “1.8” targetCompatibility = “1.8” Key method when() Executed in sub-threads Multiple callbacks can be added. fail()Failed callback done()Successful callback always() Both success and failure will call back progress() The interceptor of the callback filter() triggered by calling notify is executed in the main thread, which can forcefully change a result. resolve stands for resolution and hooks up with the done() callback reject stands for rejection and hooks up with the fail callback Notes If there is an error in multiple when, it will directly call fail and will not trigger done Common categories Deferred deferred = new DeferredObject(); This kind of object needs to manually call resolve or reject Example Promise promise = deferred. promise(); promise. done(new DoneCallback() { @Override public void onDone(Object result) { System.out.println(“done ” + result + ” ” + Thread.currentThread().getName()); } }).fail(new FailCallback() { @Override public void onFail(Object result) { System.out.println(“fail ” + result + ” ” + Thread.currentThread().getName()); } }).progress(new ProgressCallback() { @Override public void onProgress(Object progress) { System.out.println(“progress ” + progress + ” “…