/** * 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() { settle((type == DONE || type == FAIL && cont) && p.isResolved() ? DONE : FAIL, getArguments()); } });
private void loadAngular() { if(!isInjected()) { Promise loadAngular = new ScriptLoader(); loadAngular.done(new Function() { public void f() { Browser.getWindow().getConsole().info("loading angularjs succeeded."); injectModules(); } }); loadAngular.fail(new Function() { public void f() { Browser.getWindow().getConsole().warn("loading angularjs failed."); } }); } else { Browser.getWindow().getConsole().info("angularjs already loaded."); injectModules(); } }
public Promise always(Function... f) { return done(f).fail(f); }
/** * 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 String toString() { return "Deferred this=" + hashCode() + " promise=" + promise().hashCode() + " state=" + promise.state() + " restatus=" + resolve.status(); } }
public Promise getJsonP(final Settings settings) { String url = settings.getUrl().replaceFirst("callback=[^&]*", ""); url += (url.contains("?") ? "&" : "?") + "callback=jre_callback"; settings.setUrl(url); if (settings.getTimeout() < 1) { settings.setTimeout(10000); } return getXhr(settings, false) .then(new Function() { public Object f(Object... args) { Response response = arguments(0); if (response.getText().matches(jsonpCbRexp)) { return GQ.create(response.getText().replaceFirst(jsonpCbRexp, "$1")); } else { return GQuery.Deferred().reject().promise(); } } }); }