How do I know that a certain RPC callback is the correct one?

38 views
Skip to first unread message

Mohammad Al Quraian

unread,
Aug 21, 2013, 12:46:27 AM8/21/13
to google-we...@googlegroups.com
Hi,

Short story, I am making an RPC call to get a list of things, however, when I navigate quickly to another page which would make its own RPC call with different things to get. I sometimes get the previous call 'things' on top of the new 'things'.I though of appending an identifier to the given callback, but is there a better way?

Thansk

Fahmi

unread,
Aug 21, 2013, 2:32:46 AM8/21/13
to google-we...@googlegroups.com
Hai,

how u show the previous thing? is it windows pop up? 


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Mohammad Al Quraian

unread,
Aug 21, 2013, 4:16:26 AM8/21/13
to Google Web Toolkit
Does it really matter how I am showing the list? I just want to confirm that the given list is the correct one and that the old one is ignored.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/r-VPdzOYJpA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.

Jens

unread,
Aug 21, 2013, 4:22:51 AM8/21/13
to google-we...@googlegroups.com
You need to check inside the callback's onSuccess/onFailure method if the callback should still be executed. Something like:

service.callServerMethod(new Callback() {

  final Item selectedItemOnCallback = currentItem; //currentItem is an instance variable of the presenter

  void onSuccess() {
    if(selectedItemOnCallback.equals(this.currentItem)) {
       // continue work
    }
  }
}

If this.currentItem changes after the callback as been created if won't execute its onSuccess anymore.

For Activities that are recreated whenever the data changes I use an active flag that is set to true in Activity.start() and to false in Activity.onStop/onCancel. Callbacks then check this boolean flag.

-- J.
Reply all
Reply to author
Forward
0 new messages