Skip to content

Instantly share code, notes, and snippets.

@ksrb
Last active August 29, 2015 14:14
Show Gist options
  • Save ksrb/96b139ad358868f4ed74 to your computer and use it in GitHub Desktop.
Save ksrb/96b139ad358868f4ed74 to your computer and use it in GitHub Desktop.
import java.util.logging.Logger;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.Promise;
import com.google.gwt.query.client.plugins.deferred.PromiseFunction;
import com.google.gwt.user.client.Timer;
public class GWTQueryTest implements EntryPoint {
private final Logger log = Logger.getLogger("GWTQueryTest");
@Override
public void onModuleLoad() {
executionOrder();
errorHandling();
}
/**
* The error seems to disappear
*/
private void errorHandling() {
final Promise promise = timeOut(100);
promise.then(new Function() {
public void f() {
throw new Error("I want to fail");
}
}, new Function() {
public void f() {
log.info("Not here? Nope");
}
}).fail(new Function() {
public void f() {
log.info("How about here? Nope");
}
});
}
/**
* This is a duplicate of the example in http://stackoverflow.com/a/23744774
*/
private void executionOrder() {
log.info("This");
final Promise promise = timeOut(1000);
promise.then(new Function() {
public void f() {
log.info("expected from an async api");
}
});
log.info("is");
Timer timer = new Timer() {
@Override
public void run() {
log.info("He");
promise.then(new Function() {
public void f() {
log.info("BAD THINGS");
}
});
log.info("comes");
}
};
timer.schedule(2000);
}
/**
* Simple function that resolves a promise after a set delay
*
* @param delay
* @return {@link Promise}
*/
private Promise timeOut(final int delay) {
Promise promise = new PromiseFunction() {
@Override
public void f(final Deferred dfd) {
Timer t = new Timer() {
@Override
public void run() {
dfd.resolve();
}
};
t.schedule(delay);
}
};
return promise;
}
}
@ksrb
Copy link
Author

ksrb commented Feb 2, 2015

Testing if GWTQuery inherited the incorrect implementation of promises in JQuery seen in this stackoverflow question.

Answer: it seems to, the error vanishes and the execution order is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment