gist JS

Friday, September 01, 2006

GWT NestingCallbacks

Spent some time playing around with creating GWT callback "nests". Basically the idea was to have something where you could add a bunch of AsyncCallbacks into a queue, then have them fire each other off.

Basically, I wanted a blocking async call, but after reading some very good posts about this found that it's just not possible due to some javascript thread things. Moreover, it really avoids the whole point of async GUIs. (Granted, I'd planned to have a cache, so that it was unlikely to need the nested calls to be truly asynchronous, blah blah...)

Anyway I solved my problem another way, but I may play around with these nested callbacks some more. I liked the idea of big asynchronous monsters rolling around in my code.

Man I'm enjoying GWT.

public class NestingCallbacks {

List nest = new ArrayList();

* add it to the beginning
* @param nestable
public void addToNest(NestedStdAsyncCallback nestable){
nest.add(0, nestable);

public void doIt(){

NestedStdAsyncCallback cur = (NestedStdAsyncCallback) nest.get(0);



public class NestedStdAsyncCallback {

private AsyncCallback callback;

public NestedStdAsyncCallback(AsyncCallback callback) {
this.callback = callback;

public void run(List nest) {

System.out.println("run ");


if(nest.size() > 0){
System.out.println("nest size now "+nest.size());
NestedStdAsyncCallback next = (NestedStdAsyncCallback) nest.get(0);
System.out.println("end of the line");



No comments: