Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Once asynchronous, always asynchronous

395 views

Published on

articles on asynchronous communications with a focus on Javascript.
Minimizing Code Paths In Asynchronous Code, a recent post of his, is about a lesson
that I learned the hard way with GWT that applies to all RIA systems that use
asynchronous calls. His example is the same case I encountered, where a function
might return a value from a cache or might query the server to get the value: an
obvious way to do this in psuedocode is:
function getData(...arguments...,callback) {
if (... data in cache...) {
callback(...cached data...);
}
cacheCallback=anonymousFunction(...return value...) {
... store value in cache...
callback(...cached data...);
}
getDataFromServer(...arguments...,cacheCallback)
}
At first glance this code looks innocuous, but there’s a major difference between
what happens in the cached and uncached case. In the cached case, the callback()
function gets called before getData() returns — in the uncached case, the opposite
happens. What happens in this function has a global impact on the execution of the
program, opening up two code paths that complicate concurrency control and
introduce bugs that can be frustrating to debug.
This function can be made more reliable if it schedules callback() to run after the
thread it is running in completes. In Javascript, this can be done with setTimeout().
In Silverlight use System.Windows.Threading.Dispatcher. to schedule the callback

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Once asynchronous, always asynchronous

  1. 1. Generation 5 » Once Asynchronous, Always Asynchronous  Subscribe to our RSS Feed | About Us Once Asynchronous, Always Asynchronous Search for: Oliver Steele writes an excellent blog about coding style,  and has written some good articles on asynchronous communications with a focus on Javascript. Minimizing Code Paths In Asynchronous Code,  a recent post of his,  is about a lesson that I learned the hard way with GWT that applies to all RIA systems that use asynchronous calls.  His example is the same case I encountered,  where a function might return a value from a cache or might query the server to get the value:   an obvious way to do this in psuedocode is: function getData(...arguments...,callback) {    if (... data in cache...) {       callback(...cached data...);    }   cacheCallback=anonymousFunction(...return value...) {      ... store value in cache...      callback(...cached data...);   }    getDataFromServer(...arguments...,cacheCallback) } At first glance this code looks innocuous,  but there’s a major difference between what happens in the cached and uncached case.  In the cached case,  the callback() function gets called before getData() returns — in the uncached case,  the opposite happens.  What happens in this function has a global impact on the execution of the program,  opening up two code paths that complicate concurrency control and introduce bugs that can be frustrating to debug. This function can be made more reliable if it schedules callback() to run after the thread it is running in completes.  In Javascript,  this can be done with setTimeout().   In Silverlight use System.Windows.Threading.Dispatcher.  to schedule the callback to run in the UI thread. Paul Houle on April 21st 2008 in Asynchronous Communications, GWT, Silverlight Comments (1) Comment (1) Login Sort by: Date Rating Last Activity Generation 5 » The Multiton Design Pattern [...] (In a more developed application, the BlogPosting could keep a cache of the latest BlogPostingData: this could improve responsiveness by updating the BlogPostingViewer at the moment it registers, or by doing a timestamp or checksum stamp against the server to reduce the bandwidth requirements of a Fetch(), just watch out for the unintended consequences of multiple code paths.) [...] Post a new comment Enter text right here! Comment as a Guest, or login: Name Email Displayed next to your comments. Subscribe to Website (optional) Not displayed publicly. If you have a website, link to it here. None None http://gen5.info/q/2008/04/21/once-asynchronous-always-asynchronous/[1/12/2014 8:35:56 PM] Submit Comment Search Archives June 2012 (1) August 2010 (1) May 2010 (1) June 2009 (2) April 2009 (1) March 2009 (1) February 2009 (3) January 2009 (3) November 2008 (1) August 2008 (2) July 2008 (5) June 2008 (5) May 2008 (2) April 2008 (6) March 2008 (8) June 2006 (1) February 2006 (1) Categories AJAX (2) Asynchronous Communications (16) Biology (1) Books (1) Design (1) Distributed (1) Exceptions (2) Functional Programming (1) GIS (1) Ithaca (1) Japan (1) Math (1) Media (3) Nature (1) Semantic Web (3) Tools (28) CRUD (1) Dot Net (17) Freebase (2) GWT (9) Java (7) Linq (2) PHP (6) Server Frameworks (1) Silverlight (12) SQL (5) Uncategorized (1) Web (2) Analytics (1)
  2. 2. Generation 5 » Once Asynchronous, Always Asynchronous Copyright © 2013 Generation 5. WordPress Theme design. http://gen5.info/q/2008/04/21/once-asynchronous-always-asynchronous/[1/12/2014 8:35:56 PM]

×