开发者

Is it possible to overload Async Callbacks in GWT?

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开发者_C百科:

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜