16 May 18:14
Serializing closures
From: Joe Walker <joe@...>
Subject: Serializing closures
Newsgroups: gmane.comp.java.dwr.user
Date: 2008-05-16 16:15:02 GMT
Expires: This article expires on 2008-05-30
Subject: Serializing closures
Newsgroups: gmane.comp.java.dwr.user
Date: 2008-05-16 16:15:02 GMT
Expires: This article expires on 2008-05-30
In Javascript:
function delayedUpdater(message) {
dwr.util.setValue("id", message);
}
dwr.engine.setActiveReverseAjax(true);
Remote.method(delayedUpdater, 4000 /* No callback */);
And on the server:
public class Remote {
public void method(JavascriptFunction delayedUpdater, int delay) {
// Fire off a new thread to do some work
Thread work = new Thread() {
public void run() {
// Loop forever pinging the client
int i = 0;
while (true) {
Thread.currentThread().sleep(delay);
delayedUpdater.execute("Hello, World: " + (i++));
}
}
}.start();
}
}
In short: how about we create a new type: org.directwebremoting.io.JavascriptFunction, with associated converter logic so we can pass a function to the server for execution.
I was just doing some work on the dwr data store when I found myself needing something like this, and it seems like it could be generally useful.
Thoughts?
Joe.
RSS Feed