views:

44

answers:

2

Hello, I have an overloaded query method on the server side. I wanted to know if I can overload the async callback, depending upon the method signature? Or is it advised to define two different asyncallbacks? These are my two methods o the server.

public String fetchInADay(String startTime, String endTime) {}

public String fetchInADay(String startTime, String endTime, String type) {}

As an aside, Please comment:

If I am required to make two different callbacks, isnt this against the principles of OO?

+1  A: 

I assume you plan to reuse the logic implemented in onSuccess(String result). This works fine independent of what service method you call. You could even share the same instance across multiple calls.

Since javascript is single threaded you're on the safe side that the responses (onSuccess() call) of multiple async calls won't interfere with each other. But because of the asynchronous nature of these calls the order of their callbacks won't be guaranteed.

z00bs
A: 

There's no way to overload the async callback in this situation because the onSuccess methods will have the same signature.

You can pass the same AsyncCallback object to multiple services, but it won't be able to tell which service or function called it. If you want different behavior for your different service calls, you need two different callbacks.

Riley