Tuesday, August 23, 2016

Re: Completable Future in GWT 2.8-rc1

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;
}
  
  
  });

Le mardi 23 août 2016 14:35:50 UTC+2, Bauna a écrit :
Hi Zakaria,
Do you have any example of how do you use Promises from GWT?


--
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-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment