Friday, August 10, 2018

jsInterop to Promise Js function

I have a gwt module, and it is working with Jsinterop for reuse some functions that are on JS.

now we are trying to call a function on JS, thas is a promise. so when we call it from GWT it doesnt wait to the promise to resolve.. so we are getting an undefined result.

it could be replicated with this:

JS Code
bnb = { test: {client:{}} };
    bnb.test.client.Foo = function() {
         this.x = 4;
         this.y = 2;
    bnb.test.client.Foo.prototype.sum = function() {
    setTimeout(function () {
    return(thisx + this.y);
    }, 100);

    function inicial(){

package bnb.test.client;
public class FooMain {
  public static void main() {
    Foo foo = new Foo();
    int res = foo.sum();    
    Window.alert(" res : " + res);
    foo.x = 5;
    foo.y = 5;
    int res2 = foo.sum(); 
    Window.alert(" res2 : " + res2);

with the timeout acting as a promise we get the undefined return value...

How we can do to wait the promise get resolved, and then go to gwt with the correct value.

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
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment