Dear GWT'ers,

I'd like to propose a new GWT compiler transformation mechanism  
involving Async calls.

I am working on a GWT API for accessing the HTML5 Database feature[1]  
in an OpenSource project[2]. The W3C Web Database API[3] is translated  
quite literally to a Java equivalent, involving up to 5 callbacks, in  
part due to the asynchronous nature of the Database API.

Right now I am working on a higher level API involving a GWT generator  
and a set of Callback interfaces with just one set of onSuccess() and  
onFailere() callback methods, very similar to what the GWT RPC API  
looks like.

In GWT we have lots of asynchronous callback types, almost (if not)  
all having a failure path (the onFailure() method) and a success path  
(the onFailure() method):

object.aMethod(..., new AsyncCallback() {
   public void onSuccess() {
     // success path
   }
   public void onFailure() {
     // failure path
   }
}
// forward path


Q: What if we can add a transformation to the compiler which  
recognizes something like the following:

try {
   object.aMethod(...);  // aMethod is annotated with @Async or  
something
   // success path
} catch (Exception e) {
   // failure path
}
// forward path

and transforms that to an asynchronous call?

I know it is not as simple as portrayed here (all 'forward path' code  
must be called in an asynchronous manner as well, and RPC methods  
would execute the 'forward path' before any 'success/failure path')  
but it would nevertheless simplify GWT programming:

- Just a single RPC interface (no *Async anymore)
- Thread.sleep() - like function possible (games?)
- JDBC compatible API to the HTML5 database API (heh)
Perhaps other callbacks benefit as well.

There is a JavaScript library called Narrative JavaScript[4] which  
does something like this, and introduces a 'yielding operator' to help  
the NJS -> JS compiler create executable JavaScript.

Please note that I am not pleading to remove Async interfaces, I like  
the way they embody the Javascript nature of the runtime platform so  
well. It is just that for some purposes a synchronous interface makes  
more sense, and is also a bit more comprehensible to 'regular' Java  
programmers.

Is any of this feasible at all? I am curious to what you guys think of  
this.

Cheers,

Bart Guijt


[1] GWT HTML5 Database API: 
http://code.google.com/p/gwt-mobile-webkit/wiki/DatabaseApi
[2] GWT Mobile WebKit project: http://code.google.com/p/gwt-mobile-webkit/
[3] W3C Web Database: http://www.w3.org/TR/webdatabase/
[4] Narrative JavaScript: http://www.neilmix.com/narrativejs/doc/


--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to