otm:ordering_of_messages:discard_early

This is an old revision of the document!


Web applications typically update data from servers (eg. whether, time, animations, dollar rates). Developers has 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 correctly be observed. 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 discard 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.

The implementation follows: Toggle between the code and example

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

var discardEarly = function(jp) {
  if(!this.isEarly(jp)){     
    jp.proceed();
    this.updateCr(jp); //notifies that join point was executed.
  }
}

Go back the the parent page web page.

  • otm/ordering_of_messages/discard_early.1294552337.txt.gz
  • Last modified: 2011/01/09 05:52
  • by aspectscript