Giter Site home page Giter Site logo

Comments (6)

PabloZaiden avatar PabloZaiden commented on September 27, 2024 1

To do that, you can use the SignalRFuture done and onError handlers.

For instance, when you use the invoke method, you can do the following:

            proxy.invoke("myMethod", "MyParameter")
                .done(new Action<Void>() {

                    @Override
                    public void run(Void obj) throws Exception {
                        // Success
                    }
                })
                .onError(new ErrorCallback() {

                    @Override
                    public void onError(Throwable error) {
                        // Error handling
                    }
                });

from java-client.

ismailakkulak avatar ismailakkulak commented on September 27, 2024

ErrorCallback works great, but done does not work. "Done" runs on different thread from main UI Thread. If you want to dismiss loading dialog or use any UI operation, you don't it. After i saw this problem, i try to getResult() but i have to listen getResult() while operation finished. Finally, i added my callbacks.

You can try below sample code. Your advised sample code is not working for UI operation but Logger is working. If you want to work on UI Thread, you must implement new Handler for UI Thread. To summarize, you need to change callbacks for usability.

    proxy.invoke("myMethod", "MyParameter")
             .done(new Action<Void>() {
                @Override
                public void run(Void obj) throws Exception {
                    Log.i("DONE TEST", "DONE TEST");
                    Toast.makeText(context, "DONE TEST", Toast.LENGTH_SHORT).show();
                     // You must implement new Handler for UI Thread.
                }
            }).onError(new ErrorCallback() {

                @Override
                public void onError(Throwable error) {
                    Toast.makeText(context, "ERROR TEST", Toast.LENGTH_SHORT).show();
                }
            });

from java-client.

PabloZaiden avatar PabloZaiden commented on September 27, 2024

Since you don't always want to run the done handler in the UI thread, you can do the following:

   proxy.invoke("myMethod", "MyParameter")
             .done(new Action<Void>() {
                @Override
                public void run(Void obj) throws Exception {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.i("DONE TEST", "DONE TEST");
                            Toast.makeText(context, "DONE TEST", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }).onError(new ErrorCallback() {

                @Override
                public void onError(Throwable error) {
                    Toast.makeText(context, "ERROR TEST", Toast.LENGTH_SHORT).show();
                }
            });

from java-client.

ismailakkulak avatar ismailakkulak commented on September 27, 2024

I know it, but i don't like this way. I am happy with my callbacks :) You have to notice this way to other users because there is not a warning for UI thread. Thank you.

from java-client.

hunter123321000 avatar hunter123321000 commented on September 27, 2024

i try the way 1 (by handler),i can recieve the result, code as below:

hub.on("receiveHelloWorldReturn",
new SubscriptionHandler1() {
@OverRide
public void run(String msg) {
Log.i("0.03", "Result" + msg);
}
}, String.class);
hub.invoke("HelloWorldReturn");

But i try the way 2 ( direct ), i can't receive the result,

Class resultClass = null;

SignalRFuture str = hub.invoke(resultClass,
"HelloWorld2", "123");
str.done(new Action() {
@OverRide
public void run(String arg0) throws Exception {
Log.i("0.03", "arg0=" + arg0);
}
}).onError(new ErrorCallback() {
@OverRide
public void onError(Throwable error) {
Log.i("0.03", "error=" + error.toString());
}
});

could anyone help me how to recive the result by way 2?
or how to define the resultClass? thanks

from java-client.

gouravd avatar gouravd commented on September 27, 2024

@hunter123321000

You can find details in the Client Test code in the repository. But for brevity this is how you do it.

YourClass resultClass = new YourClass();

hub.invoke(resultClass.class, "HelloWorld2", "123")
.done(new Action() {
@OverRide
public void run(YourClass arg0) throws Exception {
// your code to access YourClass members
}
})
.onError(new ErrorCallback() {
@OverRide
public void onError(Throwable error) {
Log.i("0.03", "error=" + error.toString());
}
});

from java-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.