Completable Future in GWT 2.8-rc1

608 views
Skip to first unread message

zakaria amine

unread,
Aug 22, 2016, 12:53:51 PM8/22/16
to GWT Users
Hello, 

I tried using CompletableFuture in my application, and I got the famous error :

 [ERROR] Line 92: No source code is available for type java.util.concurrent.CompletableFuture<T>; did you forget to inherit a required module?

I suppose CompletableFuture is not emulated, right ? are there other alternatives ? 

Ignacio Baca Moreno-Torres

unread,
Aug 22, 2016, 1:02:00 PM8/22/16
to GWT Users

Jens

unread,
Aug 22, 2016, 1:23:39 PM8/22/16
to GWT Users

I suppose CompletableFuture is not emulated, right ? are there other alternatives ? 

Yes CompletableFuture emulation is still work in progress and not available in GWT 2.8.0.

-- J.

zakaria amine

unread,
Aug 23, 2016, 5:07:30 AM8/23/16
to GWT Users
Thanks for the info. rxjava-gwt sounds promising, it does add some complexity though...I will do with Promise for now.


Ignacio Baca Moreno-Torres

unread,
Aug 23, 2016, 6:44:30 AM8/23/16
to GWT Users
I'm curious... what problem are you trying to solve using promises (requests, events, presenter logic...)?

Pablo Nussembaum

unread,
Aug 23, 2016, 8:35:50 AM8/23/16
to google-we...@googlegroups.com
Hi Zakaria,
Do you have any example of how do you use Promises from GWT?



On 23/08/16 06:07, zakaria amine wrote:
Thanks for the info. rxjava-gwt sounds promising, it does add some complexity though...I will do with Promise for now.


--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

zakaria amine

unread,
Aug 23, 2016, 10:30:06 AM8/23/16
to GWT Users
I am working with native XMLHTTPRequest. I am trying to write a utility that simplifies the asynchornous calls, and that I can use from my applications to call Rest Services. 
Message has been deleted

zakaria amine

unread,
Aug 23, 2016, 10:40:33 AM8/23/16
to GWT Users
Hi Bauna,

here is what I did so far, and it is working fine for now: 

@JsType(isNative=true, namespace=GLOBAL)
public class Promise {
@JsConstructor
public Promise(PromiseExecutor executor){
}
//catch is a keyword in java
 @JsMethod(name = "catch")
public native Promise onException(Function reject);
public native Promise then(Function resolve);

}

@JsFunction
@FunctionalInterface
public interface PromiseExecutor {
public void executor(Function resolve, Function reject);

}

@JsFunction
@FunctionalInterface
public interface Function {
public Object call(Object event);

}

//...
Promise promise = new Promise(new PromiseExecutor() {

@Override
public void executor(Function resolve, Function reject) {
//do something 
                                resolve(value);


}

});

//...

promise.then(new Function(){
@Override
public Object call(Object resp) {
                        // Do something with resp, which is your resolved value
return null;
}
  
  
  });

Ignacio Baca Moreno-Torres

unread,
Aug 23, 2016, 2:23:11 PM8/23/16
to GWT Users
Looks like a perfect fitting for RxJava, not sure why it add complexity. Promises has no concept of subscription, so requests cannot be canceled, also you will going to need to create a lot of SAM to support generics and lambdas, this is already implemented in RxJava which is pretty mature project used in servers and androids! and now in GWT ;)

This is what can be done in RxJava and you will need lot of code to get there with promises ;)
RxGwt.click(buttonToLoadSomething)
 
// this will cancel the previous request… --v …if next click occurs before previous has done
 
.switchOnNext(event -> autoRestService.loadZeroOneOrLotOfItems()
   
.doOnSubscribe(() -> table.cleanAndShowLoading() /* do this on each new server request */)
   
.onErrorResumeNext(err -> { table.stopLoadingAndShowWhy(err); return empty(); }))
 
.filter(item -> item.name.startWith("iDontLikeThisOne"))
 
.subscribe(item -> table.addRow(item));
I'll encourage to try it out, AutoREST will just guide you to a more uniform API, instead of the RequestBuilder ModelVistor (https://github.com/intendia-oss/autorest-gwt/blob/master/gwt/src/main/java/com/intendia/gwt/autorest/client/RequestResourceBuilder.java) create your own using native XMLHTTPRequest. If you don't prefer Observable is because you haven't used them ;), hehe or not! I' just trying to promote rxjava-gwt.
Reply all
Reply to author
Forward
0 new messages