News for hackers. Stuff that matters.
Re:How LinkedIn used Node.js and HTML5 to build a better, fa... by mikeryan on Tuesday August 16, 2011 @11:30AM (#2891526)
This method has basically turned an async request into a synchronous request. One idea is that you make requests A, B, and C concurrently, parse the data, then have a handler which waits for the 3 to complete and then combines them into a single response, as opposed to cascading all the callbacks.
Re:How LinkedIn used Node.js and HTML5 to build a better, fa... by agscala on Tuesday August 16, 2011 @11:40AM (#2891580)
I understand that, but I feel like a majority of the javascript async code I've seen has all been in this format. By chance, do you have an example of handler which would wait for multiple async requests to complete?
Re:How LinkedIn used Node.js and HTML5 to build a better, fa... by mikeryan on Tuesday August 16, 2011 @11:59AM (#2891667)
So I have yet to find a project to use node on, my case is mostly for Async AJAX requests.

Here's a very simple version (which I admit to still using occasionally)

  RequestHandler = {
      numberOfRequests: 3
      makeRequests: function() {
          var __this = this;
          a(function() {
              // Parse Data
              __this.completeRequest();
          })
          b(function() {
              // Parse Data
              __this.completeRequest();
          })
          c(function() {
              // Parse Data
              __this.completeRequest();
          })
      },
      completeRequest: function() {
         this.numberOfRequests--;
         if(this.numberOfRequests == 0 ) this.doDone();
      }
      doDone: function() {
        // We now have all data, do what we will.
      } 
  }
  RequestHandler.makeRequests();
Re:How LinkedIn used Node.js and HTML5 to build a better, fa... by fatjonny on Tuesday August 16, 2011 @11:48AM (#2891628)
You could write your own way of doing it or use an existing flow control library. There are lots. :)

https://github.com/joyent/node/wiki/modules#wiki-async-flow

For a specific example, look at async.parallel: https://github.com/caolan/async

Re:How LinkedIn used Node.js and HTML5 to build a better, fa... by agscala on Tuesday August 16, 2011 @12:00PM (#2891669)
I wish I knew about this kind of thing last time I hacked on node.js... I would have had such better & cleaner code. This clears up a lot. Thanks