otm:ordering_of_messages:discard_late

This is an old revision of the document!


Web applications typically update data from servers (eg. whether, time, animations, dollar rates). Developers have to overcome the issue of using obsolete data due to a late response of a server. For example, consider a website that shows an animation, rotation of the Earth, using several ajax requests. If responses of ajax requests are retrieved in wrong order, the animation cannot be observed correctly. A solution could be to wait for all frames of the animation, however, this solution could delay to much the animation. A better solution is to discard the late frames to show the animation. The DiscardLate strategy discards the late responses of ajax requests (obsolete responses).

When the activate order is clicked, the animation always is showed a correct flow (right to left). When the deactivate order is clicked, the animation is showed a random flow. NOTE: You have to wait until a new animation to see the effect over the animation.

The implementation follows: Toggle between the code and example

The DiscardLate strategy is implemented how a TM advice, which is a JavaScript function, that is executed every time a response of ajax request is retrieved:

var discardLate = function(jp) {
  if(!this.isLate(jp)){     //is obsolete this join point?
    jp.proceed();
    this.updateCr(jp); //notifies that join point was executed.
  }
}

Go back the the parent page web page.

  • otm/ordering_of_messages/discard_late.1294665734.txt.gz
  • Last modified: 2011/01/10 13:22
  • by aspectscript