public void f(Deferred dfd) { try { Response response = httpClient(settings, cors); int status = response.getStatusCode(); if (status <= 0 || status >= 400) { String statusText = status <= 0 ? "Bad CORS" : response.getStatusText(); dfd.reject(new RequestException("HTTP ERROR: " + status + " " + statusText + "\n" + response.getText()), null); } else { dfd.resolve(response, null); } } catch (Exception e) { e.printStackTrace(); dfd.reject(e, null); } } };
/** * Returns a dynamically generated Promise that is resolved once all actions * in the named queue have ended. */ public Promise promise(final String name) { final Promise.Deferred dfd = Deferred(); // This is the unique instance of the resolve function which will be added to each element. final Function resolve = new Function() { // Because it is an inner function, the counter cannot final outside the function int count = 1; // Inner functions don't have constructors, we use a block to initialize it { for (Element elem : elements()) { // Add this resolve function only to those elements with active queue if (queue(elem, name, null) != null) { emptyHooks(elem, name).add(this); count++; } } } public void f() { if (--count == 0) { dfd.resolve(QueuePlugin.this); } } }; // Run the function and resolve it in case there are not elements with active queue resolve.f(this, name); return dfd.promise(); }
/** * This function is called when the previous promise in the pipe * is resolved. */ public final Object f(Object... args) { return dfd != null && (cache == CacheType.ALL || cache == CacheType.RESOLVED && dfd.promise().isResolved() || cache == CacheType.REJECTED && dfd.promise().isRejected()) ? dfd.promise() : new PromiseFunction() { public void f(Deferred dfd) { FunctionDeferred.this.resolve = resolve; FunctionDeferred.this.reject = reject; FunctionDeferred.this.dfd = dfd; FunctionDeferred.this.f(dfd); } }; }
@Override public void onFailure(Exception reason) { dfd.reject(reason); }
public void f(Deferred dfd) { dfd.resolve(o); } };
/** * Reset the cache so as a new invocation to this function will * execute it instead of restoring old values from cache. */ public FunctionDeferred resetCache() { if (dfd != null && !dfd.promise().isPending()) { dfd = null; } return this; } }
public void f(final com.google.gwt.query.client.Promise.Deferred dfd) { if ("complete" == $(document).prop("readyState")) { dfd.resolve(); } else { $(document).on("load", new Function() { public void f() { dfd.resolve(); } }); } } }.done(fncs);
@Override public void onSuccess(Void result) { dfd.resolve(); } }).setWindow(ScriptInjector.TOP_WINDOW).inject();
private Promise then(boolean continueFlow, final Function... f) { final Deferred newDfd = new com.google.gwt.query.client.plugins.deferred.Deferred(); done(new ThenFunction(newDfd, f, DONE, continueFlow)); fail(new ThenFunction(newDfd, f, FAIL, continueFlow)); progress(new ThenFunction(newDfd, f, PROGRESS, continueFlow)); return newDfd.promise(); }
public void f() { if (--count == 0) { dfd.resolve(QueuePlugin.this); } } };