* in the queue.
*/
public void dequeueIfNotDoneYet(Element elem, String name, Object object) {
- Queue<?> queue = queue(elem, name, null);
+ Queue queue = queue(elem, name, null);
if (queue != null && object.equals(queue.peek())) {
dequeueCurrentAndRunNext(elem, name);
}
}
private void stop(Element elem, String name, boolean clear, boolean jumpToEnd) {
- Queue<?> q = queue(elem, name, null);
+ Queue q = queue(elem, name, null);
if (q != null) {
Object f = q.peek();
if (clear) {
}
return true;
}
+
+ public String status() {
+ return (stack == null ? 0 : stack.length()) + " " + done;
+ }
}
private static class ThenFunction extends Function {
// Used internally in ThenFunction, to resolve deferred object
private class DoFunction extends Function {
+ int type;
+ public DoFunction(int type) {
+ this.type = type;
+ }
public void f() {
if (type == 0) dfd.resolve(getArguments());
if (type == 1) dfd.reject(getArguments());
}
public void f() {
- Object[] args = getArguments();
- Function doIt = new DoFunction().setArguments(args);
+ final Object[] args = getArguments();
+ Function doIt = new DoFunction(type).setArguments(args);
if (filter != null) {
// We filter resolved arguments with the filter function
Object newArgs = filter.setArguments(args).f(args);
- // If filter function returns a promise we pipeline it
+ // If filter function returns a promise we pipeline it and don't resolve this
if (newArgs instanceof Promise) {
Promise p = (Promise) newArgs;
- if (type == 0) p.done(doIt);
- if (type == 1) p.fail(doIt);
- if (type == 2) p.progress(doIt);
+ p.done(new DoFunction(0));
+ p.fail(new DoFunction(1));
+ p.progress(new DoFunction(2));
return;
+ // Otherwise we change the arguments with the new args
} else if (newArgs.getClass().isArray()) {
doIt.setArguments((Object[])newArgs);
} else {
doIt.setArguments(newArgs);
}
}
+ // run the function with the new args to resolve this deferred
doIt.f();
}
}
import com.google.gwt.core.client.Duration;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.query.client.Promise.Deferred;
import com.google.gwt.query.client.plugins.ajax.Ajax;
import com.google.gwt.query.client.plugins.deferred.Callbacks;
import com.google.gwt.query.client.plugins.deferred.Callbacks.Callback;
});
}
+ public void testDeferredAjaxThenFail() {
+ delayTestFinish(5000);
+ GQuery
+ .when(new PromiseFunction() {
+ public void f(Deferred dfd) {
+ dfd.resolve("message");
+ }
+ })
+ .then(new Function() {
+ public Object f(Object... args) {
+ return new PromiseFunction() {
+ public void f(Deferred dfd) {
+ dfd.resolve(arguments);
+ }
+ };
+ }
+ })
+ .then(new Function() {
+ public Object f(Object... args) {
+ return new PromiseFunction() {
+ public void f(Deferred dfd) {
+ dfd.reject(arguments);
+ }
+ };
+ }
+ })
+ .done(new Function() {
+ public void f() {
+ finishTest();
+ fail();
+ }
+ })
+ .fail(new Function() {
+ public void f() {
+ assertEquals("message", arguments(0));
+ finishTest();
+ }
+ });
+ }
+
public void testDeferredQueueDelay() {
final int delay = 300;
final double init = Duration.currentTimeMillis();